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 student with a password of student.
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/student
View 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 root user at the shell prompt.
[student@serverX ~]$suPassword:redhat
View 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/student
View 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/bin
Exit the shell to return to the student user.
[root@serverX student]#exitexit
Switch to root with the dash and explore characteristics of the new environment.
Become the root user at the shell prompt. Be sure all the login scripts are also executed.
[student@serverX ~]$su -Password:redhat
View 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/root
View 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/bin
Exit the shell to return to the student user.
[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/0
Make a backup of a configuration file in the /etc directory.
[student@serverX ~]$cp /etc/motd /etc/motdOLDcp: cannot create regular file ‘/etc/motdOLD’: Permission denied[student@serverX ~]$sudo cp /etc/motd /etc/motdOLD
Remove the /etc/motdOLD file 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/motdOLD
Edit a configuration file in the /etc directory.
[student@serverX ~]$echo "Welcome to class" >> /etc/motd-bash: /etc/motd: Permission denied[student@serverX ~]$sudo vim /etc/motd