This is an old revision of the document!
Use visudo command to update the file /etc/sudoers, do not manual edit
Which password will be asked ? default is target user password, and for group wheel, source user password:
Defaults targetpw Defaults:%wheel !targetpw
In the following sudo entry:
<user> <host>=(<taget_user>[:<target_group>]) <cmd>
Example:
alan ALL = (root, bin : operator, system) /bin/ls, /bin/kill %adm ALL=(ALL) NOPASSWD: ALL
Here, alan is allowed to run the two commands /bin/ls and /bin/kill as root (or bin), possibly with additional operator or system groups privileges.
So alan may choose to run ls as the bin user and with operator's group privileges like this (additional operator groups privileges):
# sudo -u bin -g operator /bin/ls /whatever/directory
[root@aix001]/etc/sudoers.d> cat zabbix %AIXUSERS ALL=(root) NOPASSWD: /usr/bin/vi /etc/zabbix/* %AIXUSERS ALL=(root) NOPASSWD: /etc/rc.d/init.d/zabbix-agent %testaixgrp ALL=(root) NOPASSWD: /usr/bin/vi /etc/zabbix/* %testaixgrp ALL=(root) NOPASSWD: /etc/rc.d/init.d/zabbix-agent [root@aix001]/etc/sudoers.d> su - myaixuser01 [myaixuser01@aix001]/home/myaixuser01> sudo vi /etc/zabbix/zabbix_agentd.d/toto [myaixuser01@aix001]/home/myaixuser01> sudo /etc/rc.d/init.d/zabbix-agent start Zabbix agent started
Using sudo -i is virtually the same as the sudo su command with one exception: it does not directly interact with the root user.
Much like sudo su, the -i flag allows a user to get a root environment without having to know the root account password. sudo -i is also very similar to using sudo su: it’ll read all of the environmental files (“.profile”, etc.) and set the environment inside the shell.
Where it differs from sudo su is that sudo -i is a much cleaner way of gaining root and a root environment without directly interacting with the root user.
To clarify: with sudo su, you’re using more than one root setuid command in the background. This makes it much more challenging to figure out which environmental variables will be kept and which will be changed (when swapping to the root environment). This is not true with sudo -i. Because of this, most people view it as the preferred method to gain root without logging in directly.
In simpler language: sudo -i will give you a “clean” root login in your “/root” folder, which is the “home” folder for the root user.
This command summons a shell with your $SHELL variable.
The -s switch for the sudo command reads the $SHELL variable of the current user executing commands. This command works as if the user is running sudo /bin/bash, if the shell the user comes from is bash.
In our case, sudo -s gave us the fish interactive shell, as we previously installed fish as our default shell, so it would be as if we ran sudo /usr/bin/fish.