RHCSA Rapid Track
In this lab, you will practice running commands as root.
Outcomes
Use the su with and without login scripts to switch users. Use sudo to run commands with privilege.
Reset your serverX system.
Log into the GNOME desktop on serverX as
studentwith a password ofstudent.Open a window with a Bash prompt.
Select → → .
Explore characteristics of the current student login environment.
View the user and group information and display the current working directory.
[student@serverX ~]$iduid=1000(student) gid=1000(student) groups=1000(student),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023[student@serverX ~]$pwd/home/studentView the variables which specify the home directory and the locations searched for executable files.
[student@serverX ~]$echo $HOME/home/student[student@serverX ~]$echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/student/.local/bin:/home/student/bin
Switch to root without the dash and explore characteristics of the new environment.
Become the
rootuser at the shell prompt.[student@serverX ~]$suPassword:redhatView the user and group information and display the current working directory. Note the identity changed, but not the current working directory.
[root@serverX student]#iduid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023[root@serverX student]#pwd/home/studentView the variables which specify the home directory and the locations searched for executable files. Look for references to the student and root accounts.
[root@serverX student]#echo $HOME/root[root@serverX student]#echo $PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/home/student/.local/bin:/home/student/binExit the shell to return to the
studentuser.[root@serverX student]#exitexit
Switch to root with the dash and explore characteristics of the new environment.
Become the
rootuser at the shell prompt. Be sure all the login scripts are also executed.[student@serverX ~]$su -Password:redhatView the user and group information and display the current working directory.
[root@serverX ~]#iduid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023[root@serverX ~]#pwd/rootView the variables which specify the home directory and the locations searched for executable files. Look for references to the student and root accounts.
[root@serverX ~]#echo $HOME/root[root@serverX ~]#echo $PATH/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/binExit the shell to return to the
studentuser.[root@serverX ~]#exitlogout
Run several commands as student which require root access.
View the last 5 lines of the
/var/log/messages.[student@serverX ~]$tail -5 /var/log/messagestail: cannot open ‘/var/log/messages’ for reading: Permission denied[student@serverX ~]$sudo tail -5 /var/log/messagesFeb 3 15:07:22 localhost su: (to root) root on pts/0 Feb 3 15:10:01 localhost systemd: Starting Session 31 of user root. Feb 3 15:10:01 localhost systemd: Started Session 31 of user root. Feb 3 15:12:05 localhost su: (to root) root on pts/0 Feb 3 15:14:47 localhost su: (to student) root on pts/0Make a backup of a configuration file in the
/etcdirectory.[student@serverX ~]$cp /etc/motd /etc/motdOLDcp: cannot create regular file ‘/etc/motdOLD’: Permission denied[student@serverX ~]$sudo cp /etc/motd /etc/motdOLDRemove the
/etc/motdOLDfile that was just created.[student@serverX ~]$rm /etc/motdOLDrm: remove write-protected regular empty file ‘/etc/motdOLD’? y rm: cannot remove ‘/etc/motdOLD’: Permission denied[student@serverX ~]$sudo rm /etc/motdOLDEdit a configuration file in the
/etcdirectory.[student@serverX ~]$echo "Welcome to class" >> /etc/motd-bash: /etc/motd: Permission denied[student@serverX ~]$sudo vim /etc/motd