Bookmark this page

Guided Exercise: Controlling New File Permissions and Ownership

In this lab, you will control default permissions on new files using the umask command and setgid permission.

Outcomes

  • Create a shared directory where new files are automatically owned by the group ateam.

  • Experiment with various umask settings.

  • Adjust default permissions for specific users.

  • Confirm your adjustment is correct.

Reset your serverX system. Run lab permissions setup to create the alice account. The password for alice is password.

  1. Log in as alice on your serverX virtual machine and open a window with a Bash prompt. Use the umask command without arguments to display Alice's default umask value.

    [alice@serverX ~]$ umask
    0002
    
  2. Create a new directory /tmp/shared and a new file /tmp/shared/defaults to see how the default umask affects permissions.

    [alice@serverX ~]$ mkdir /tmp/shared
    [alice@serverX ~]$ ls -ld /tmp/shared
    drwxrwxr-x. 2 alice alice 6 Jan 26 18:43 /tmp/shared
    [alice@serverX ~]$ touch /tmp/shared/defaults
    [alice@serverX ~]$ ls -l /tmp/shared/defaults
    -rw-rw-r--. 1 alice alice 0 Jan 26 18:43 /tmp/shared/defaults
    
  3. Change the group ownership of /tmp/shared to ateam and record the new ownership and permissions.

    [alice@serverX ~]$ chown :ateam /tmp/shared
    [alice@serverX ~]$ ls -ld /tmp/shared
    drwxrwxr-x. 2 alice ateam 21 Jan 26 18:43 /tmp/shared
    
  4. Create a new file in /tmp/shared and record the ownership and permissions.

    [alice@serverX ~]$ touch /tmp/shared/alice3
    [alice@serverX ~]$ ls -l /tmp/shared/alice3
    -rw-rw-r--. 1 alice alice 0 Jan 26 18:46 /tmp/shared/alice3
    
  5. Ensure the permissions of /tmp/shared cause files created in that directory to inherit the group ownership of ateam.

    [alice@serverX ~]$ chmod g+s /tmp/shared
    [alice@serverX ~]$ ls -ld /tmp/shared
    drwxrwsr-x. 2 alice ateam 34 Jan 26 18:46 /tmp/shared
    [alice@serverX ~]$ touch /tmp/shared/alice4
    [alice@serverX ~]$ ls -l /tmp/shared/alice4
    -rw-rw-r--. 1 alice ateam 0 Jan 26 18:48 /tmp/shared/alice4
    
  6. Change the umask for alice such that new files are created with read-only access for the group and no access for other users. Create a new file and record the ownership and permissions.

    [alice@serverX ~]$ umask 027
    [alice@serverX ~]$ touch /tmp/shared/alice5
    [alice@serverX ~]$ ls -l /tmp/shared/alice5
    -rw-r-----. 1 alice ateam 0 Jan 26 18:48 /tmp/shared/alice5
    
  7. Open a new Bash shell as alice and view the umask.

    [alice@serverX ~]$ umask
    0002
    
  8. Change the default umask for alice to prohibit all access for users not in their group.

    [alice@serverX ~]# echo "umask 007" >> ~/.bashrc
    [alice@serverX ~]# 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 functions
    umask 007
    
  9. Log out and back into serverX as alice and confirm that the umask changes you made are persistent.

    [alice@serverX ~]$ umask
    0007
    
Revision: rh124-7-1b00421