Monday, July 2, 2018

SUDO COMMANDS EXAMPLES

Syntax for sudoers file is as below

USER_ALIAS HOST_ALIAS=EFECTIVE_USER) COMMAND_ALIAS

Now Let's understand the components.

USER_ALIAS : User aliases are used to specify users, groups or netgroups.

examples:
User_Alias ADMINS = %admin
User_Alias WEBMASTERS = tom,rob
User_Alias LIMITED_USERS = !WEBMASTERS, !ADMINS

HOST_ALIAS: list of hostname, ip addresses, networks and netgroups

examples:
Host_Alias SERVERS = 192.168.0.1, 192.168.0.2, server1
Host_Alias WORKSTATIONS = 192.168.0.0/255.255.255.0, !SERVERS

EFECTIVE_USER : Who can run what as who

examples:
User_Alias EFECTIVE_USER = sam,rob

COMMAND_ALIAS: Lists of commands ( full path of commands) and directories

examples
Cmnd_Alias        SBIN_CMDS = /sbin
Cmnd_Alias        APP_CMDS =  /usr/bin/passwd, /sbin/service httpd *, /sbin/ifconfig : DB_CMDS = /bin/su – admin, /home/admin/zabbix_server : ADMIN_CMDS = /sbin/, /usr/sbin/

Now let's try some usecase

1) user rob to run /bin/su command with root privileges. Same time it restricts using any options/argument and login to root.
rob          ALL = (root)        /bin/su [!-]*[!root]*

2) This lets the admins run all the admin commands on the servers
ADMINS SERVERS= ADMIN_CMDS

3) This lets "rob" shutdown his own machine without a password
rob rob-machine= NOPASSWD: SHUTDOWN_CMDS

4) rob should run command hwclock only ( without any arguments)
rob        ALL = (ALL)          /sbin/hwclock “”

No comments:

Post a Comment

Renew k8s certificates

Check If certificate expires: amikum@~:03:06:54(⎈ |local-cluster:default):sudo kubeadm certs check-expiration CERTIFICATE                EXP...