RHCSA Rapid Track
In this exercise, you will control the permissions on new files created in a directory by using umask settings and the setgid permission.
Outcomes
You should be able to:
Create a shared directory where new files are automatically owned by the
operatorsgroup.Experiment with various umask settings.
Adjust default permissions for specific users.
Confirm your adjustment is correct.
Log in to workstation as student using student as the password.
On workstation, run the lab perms-default start command.
The command runs a start script that determines if servera is reachable on the network.
The script also creates the operators group and the operator1 user on servera.
[student@workstation ~]$lab perms-default start
Use the ssh command to log in to
serveraas thestudentuser.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Use the su command to switch to the
operator1user usingredhatas the password.[student@servera ~]$su - operator1Password:redhat[operator1@servera ~]$Use the umask command to list the
operator1user's default umask value.[operator1@servera ~]$umask0002Create a new directory named
/tmp/shared. In the/tmp/shareddirectory, create a file nameddefaults. Look at the default permissions.Use the mkdir command to create the
/tmp/shareddirectory. Use the ls -ld command to list the permissions of the new directory.[operator1@servera ~]$mkdir /tmp/shared[operator1@servera ~]$ls -ld /tmp/shareddrwxrwxr-x. 2 operator1 operator1 6 Feb 4 14:06 /tmp/sharedUse the touch command to create a file named
defaultsin the/tmp/shareddirectory.[operator1@servera ~]$touch /tmp/shared/defaultsUse the ls -l command to list the permissions of the new file.
[operator1@servera ~]$ls -l /tmp/shared/defaults-rw-rw-r--. 1 operator1 operator1 0 Feb 4 14:09 /tmp/shared/defaults
Change the group ownership of
/tmp/sharedtooperators. Confirm the new ownership and permissions.Use the chown command to change the group ownership of the
/tmp/shareddirectory tooperators.[operator1@servera ~]$chown :operators /tmp/sharedUse the ls -ld command to list the permissions of the
/tmp/shareddirectory.[operator1@servera ~]$ls -ld /tmp/shareddrwxrwxr-x. 2 operator1 operators 22 Feb 4 14:09 /tmp/sharedUse the touch command to create a file named
groupin the/tmp/shareddirectory. Use the ls -l command to list the file permissions.[operator1@servera ~]$touch /tmp/shared/group[operator1@servera ~]$ls -l /tmp/shared/group-rw-rw-r--. 1 operator1 operator1 0 Feb 4 17:00 /tmp/shared/groupNote
The group owner of the
/tmp/shared/groupfile is notoperatorsbutoperator1.
Ensure that files created in the
/tmp/shareddirectory are owned by theoperatorsgroup.Use the chmod command to set the group ID to the
operatorsgroup for the/tmp/shareddirectory.[operator1@servera ~]$chmod g+s /tmp/sharedUse the touch command to create a new file named
operations_database.txtin the/tmp/shareddirectory.[operator1@servera ~]$touch /tmp/shared/operations_database.txtUse the ls -l command to verify that the
operatorsgroup is the group owner for the new file.[operator1@servera ~]$ls -l /tmp/shared/operations_database.txt-rw-rw-r--. 1 operator1 operators 0 Feb 4 16:11 /tmp/shared/operations_database.txt
Create a new file in the
/tmp/shareddirectory namedoperations_network.txt. Record the ownership and permissions. Change theumaskforoperator1. Create a new file calledoperations_production.txt. Record the ownership and permissions of theoperations_production.txtfile.Use the touch command to create a file called
operations_network.txtin the/tmp/shareddirectory.[operator1@servera ~]$touch /tmp/shared/operations_network.txtUse the ls -l command to list the permissions of the
operations_network.txtfile.[operator1@servera ~]$ls -l /tmp/shared/operations_network.txt-rw-rw-r--. 1 operator1 operators 5 Feb 0 15:43 /tmp/shared/operations_network.txtUse the umask command to change the umask for the
operator1user to 027. Use the umask command to confirm the change.[operator1@servera ~]$umask 027[operator1@servera ~]$umask0027Use the touch command to create a new file named
operations_production.txtin the/tmp/shared/directory. Use the ls -l command to ensure that newly created files are created with read-only access for theoperatorsgroup and no access for other users.[operator1@servera ~]$touch /tmp/shared/operations_production.txt[operator1@servera ~]$ls -l /tmp/shared/operations_production.txt-rw-r-----. 1 operator1 operators 0 Feb 0 15:56 /tmp/shared/operations_production.txt
Open a new terminal window and log in to
serveraasoperator1.[student@workstation ~]$ssh operator1@servera...output omitted...[operator1@servera ~]$List the umask value for
operator1.[operator1@servera ~]$umask0002Change the default umask for the
operator1user. The new umask prohibits all access for users not in their group. Confirm that the umask has been changed.Use the echo command to change the default umask for the
operator1user to 007.[operator1@servera ~]$echo "umask 007" >> ~/.bashrc[operator1@servera ~]$cat ~/.bashrc# .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # Uncomment the following line if you don't like systemctl's auto-paging feature: # export SYSTEMD_PAGER= # User specific aliases and functionsumask 007Log out and log in again as the
operator1user. Use the umask command to confirm that the change is permanent.[operator1@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$ssh operator1@servera...output omitted...[operator1@servera ~]$umask0007
On
servera, exit from all theoperator1and thestudentuser shells.Warning
Exit from all shells opened by
operator1. Failure to exit from all shells will cause the finish script to fail.[operator1@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$
This concludes the guided exercise.