System Administrators rarely log into a system as `root`, due to a number of security risks. Some distributions even disable the `root` account to begin with. Restricting the ability to use `root` privileges to selected users is an important part of maintaining a secure system. In this activity, you will learn how to secure the `su` and `sudo` commands by restricting their use to members of the `wheel` group.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Confirm Your User Is in the wheel Group and Set the /usr/bin/sudo and /usr/bin/su Files so They Can Be Executed by the root User and wheel Group
- Use the
idandgroupscommands to confirm yourwheelgroup membership:id groupsUse
sudoto become the root user:sudo -iRun
chgrpto set thewheelgroup as the owner of/usr/bin/sudoand/usr/bin/su:chgrp wheel /usr/bin/sudo /usr/bin/suUse
chmodto set the most secure permissions, and allow therootuser andwheelgroup to executesudoandsu:chmod 4110 /usr/bin/sudo /usr/bin/suRun
ls -lon either of those to confirm. - Use visudo to Confirm, Create, or Uncomment Entry Allowing wheel Group to Use sudo
- To modify or verify
/etc/sudoersallows the wheel group to use sudo, use thevisudocommand:visudoWe need a line that looks like this:
%wheel ALL=(ALL) ALLIt may already be there, or it may be there and commented out. It’s usually down in the vicinity of the
rootline. Save changes to the file and exit. Usegrepto verify the line is there.grep wheel /etc/sudoers - Uncomment or Create a Line in /etc/pam.d/su to Require wheel Group Membership for Using the su Command
- Using the editor of your choice, uncomment or create an additional “auth” test below the line ending with
pam_rootok.so. The line should look like this:auth required pam_wheel.so use_uid - Create a sysadmin User, Make Them a Member of the wheel Group, Set Their Password, and Verify sysadmin Is Able to Use sudo and su
- Create the
sysadminuser and make them a member of thewheelgroup:useradd -G wheel sysadminRunning it this way would work too:
useradd sysadmin usermod -aG wheel sysadminNow we can set the
sysadminuser password:passwd sysadminVerify
sysadmincan executesuandsudo:su - sysadmin sudo tail -n1 /etc/shadow su -l cloud_user exit exit - Create a User, sysuser, Who Is Not a Member of the wheel Group, Set Their Password, and Verify That They Are Not Able to Use sudo and su
- Create the
sysuseruser and do not make them a member of thewheelgroup:useradd sysuserSet the
sysuseruser password.passwd sysuserVerify
sysusercannot executesuandsudo:su --login sysuser sudo tail -n1 /etc/shadow su -l cloud_user exit exitThe
sudoand followingsucommands should have both failed.