How to configure su and sudo Access (Part I of II)
There are the following ways that user jdoe, acting as a normal user, can execute commands requiring superuser privileges:
- Log out of the desktop session, and log back in as user root, which is a VERY bad idea.
- Enter “su -” and entering the superuser password.
Requires that you know the superuser's password.
Will allow user jdoe to switch to the user root account. Once switched to user root’s account, user jdoe can execute any command as the superuser until the “exit” command is executed. Convenient when user jdoe needs to enter more than one command as the superuser. - su -c {command}
Requires that you know the superuser's password.
Will allow user jdoe to execute the single {command} as the superuser. This sequence needs to be entered each time a command requiring superuser privileges is typed, so it is not very convenient if more than one command requiring superuser privileges needs to be executed. - sudo {command}
Requires that user jdoe be configured in the /etc/sudoers file, which can only be done by someone with superuser privileges (one of the things that justifies System Administrators, at least until we know what they know).
The /etc/sudoers file can be configured (using the visudo command) to limit the commands that user jdoe can execute using sudo, for security purposes.
Ask the System Administrator to modify the /etc/sudoers file to add privileged commands that you run often. The idea is to keep user root’s (a.k.a., the superuser) password from all but the System Administrator.
Once configured, user jdoe enters jdoe’s password (NOT the superuser password). For a period of about 5 minutes, user jdoe may execute commands normally requiring superuser privileges without being prompted for a password.
In the event that user root’s password does get out, it will not do a user any good, as we are going to lock down the use of the su command, forcing users to be in the “wheel” group before they may execute the su command. Only trusted users will be placed in the wheel group.
Each time the user issues a sudo command, this is logged. Each time a sudo command request fails, an e-mail is sent to the System Administrator. So, if a user attempts to execute commands with sudo that the user is not configured to execute, the System Administrator will know about it.
Lock down su command
To lock down the su command, we will require all users with access to the su command to be members of the wheel group. When Fedora 11 is installed out-of-the-box, the wheel group is not configured with any users other than user root.
Enter as follows to add user jdoe, to the wheel group:
Code:
[jdoe@Eng-Lab-004 ~]$ su -
Password: {user root’s password}
[root@Eng-Lab-010 ~]# gpasswd -a jdoe wheel
Adding user jdoe to group wheel
[root@Eng-Lab-010 ~]#
The /etc/pam.d/su file manages the configuration of the su command.
Enter as follows to edit the /etc/pam.d/su file (after first making a backup copy):
Code:
[root@Eng-Lab-010 ~]# cp -a /etc/pam.d/su /etc/pam.d/su.orig
[root@Eng-Lab-010 ~]# vim /etc/pam.d/su
and modify from:
Code:
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth include system-auth
account include system-auth
password include system-auth
session include system-auth
session optional pam_xauth.so
to:
Code:
#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid
auth include system-auth
account include system-auth
password include system-auth
session include system-auth
session optional pam_xauth.so
Save and close the file.
This will force users to be in the wheel group before they may execute the su command.
Log out.
Log back in as user jdoe.
Users not a member of the “wheel” group will receive the following response whenever they attempt to use the su command, even if they know user root’s password:
Code:
[jsmith@Eng-Lab-004 ~]$ su -
Password: {user root’s password}
su: incorrect password
[jsmith@Eng-Lab-004 ~]$
Configure /etc/sudoers for user jdoe
Enter as follows to configure the /etc/sudoers file to allow user jdoe permission to execute any command in the /usr/bin/ and /bin directories on hosts Eng-Lab-003, Eng-Lab-004, and Eng-Lab-005 (i.e., the local computer’s in jdoe’s subnet).
Display the compiled-in defaults for sudo
Enter as follows to display the compiled-in defaults for sudo.
Code:
[jdoe@Eng-Lab-004 ~]$ su -
Password: {user root’s password}
[root@Eng-Lab-004 pam.d]# sudo -V
.
. LOTS of output
.
[root@Eng-Lab-004 pam.d]#
Note that:
- If the user is not in the sudoers file, and issues the sudo command, an e-mail is sent to the System Administrator.
- The first time the user runs the sudo command, they get a “lecture” on the “proper” use of the sudo command.
- Once the user has issued the sudo command and entered the user’s password, future use of the sudo command does not require inputting the password for 5 minutes.
- All e-mail sent by sudo is sent to user root (i.e., the System Administrator). This can be redirected by editing /etc/aliases and running newaliases.
- /bin/vi is the default editor used by the visudo application.
Add user jdoe to the /etc/sudoers file
The following is an example /etc/sudoers file that we have found works in the Lab. It may be customized by the Project’s System Administrator to meet Project specific goals. For instance, once more users have been added to this computer, these users may be added to the User_Alias line.
NOTE: You should understand the following before using or changing, as this is what I use in the Lab, you will likely have different requirements.
Launch /usr/sbin/visudo, and add the following to the /etc/sudoers file at the indicated points:
Code:
[root@Eng-Lab-004 ~]# visudo
.
.
.
# Host alias specification
Host_Alias LAB = Eng-Lab-003, Eng-Lab-004, Eng-Lab-005, Eng-Lab-010
.
.
.
# User alias specification
User_Alias TRUSTED = jdoe, jsmith
.
.
.
# Cmnd alias specification
Cmnd_Alias ADMIN = /bin/,\
!/bin/su,\
/usr/bin/,\
/usr/sbin/groupadd,\
/usr/sbin/alternatives
.
.
.
# Defaults specification
Defaults:TRUSTED insults
Defaults@LAB log_year, logfile=/var/log/sudo.log
.
.
.
# User privilege specification
root ALL=(ALL) ALL
TRUSTED LAB = (ALL) ADMIN
# Uncomment to allow people in group wheel to run all commands
# %wheel ALL=(ALL) ALL ⇐= NOTE: Don’t uncomment
# Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL ⇐= NOTE: Don’t uncomment
.
.
.
Save and close the /etc/sudoers file (i.e., press the Esc key, enter “:”, then type “wq” and press ENTER).
No need to log out and back in, the /etc/sudoers file is immediately available. Just exit from the superuser, as follows:
Code:
[root@Eng-Lab-004 ~]# exit
[jdoe@Eng-Lab-004 ~]$
See next post for PartII