Bookmark this page

Guided Exercise: Manage File System Permissions from the Command Line

In this exercise, you use file system permissions to create a directory in which all members of a particular group can add and delete files.

Outcomes

  • Create a collaborative directory that all members of a group can access.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start perms-cli

Instructions

  1. From workstation, log in to servera as the student user and switch to the root user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Create the /home/consultants directory.

    [root@servera ~]# mkdir /home/consultants
  3. Change the group ownership of the consultants directory to consultants.

    [root@servera ~]# chown :consultants /home/consultants
  4. Modify the permissions of the consultants group to allow its group members to create files in, and delete files from, the /home/consultants directory.

    The current permissions forbid others from accessing the files. You must set the appropriate permissions.

    1. Verify that the permissions of the consultants group allow its group members to create files in, and delete files from, the /home/consultants directory.

      Note that the consultants group currently does not have write permission.

      [root@servera ~]# ls -ld /home/consultants
      drwxr-xr-x.  2 root    consultants       6 Mar  1 12:08 /home/consultants
    2. Add write permission to the consultants group. Use the symbolic method for setting the appropriate permissions.

      [root@servera ~]# chmod g+w /home/consultants
      [root@servera ~]# ls -ld /home/consultants
      drwxrwxr-x. 2 root consultants 6 Mar  1 13:21 /home/consultants
    3. Forbid others from accessing files in the /home/consultants directory. Use the octal method for setting the appropriate permissions.

      [root@servera ~]# chmod 770 /home/consultants
      [root@servera ~]# ls -ld /home/consultants
      drwxrwx---. 2 root consultants 6 Mar  1 12:08 /home/consultants/
  5. Exit the root shell and switch to the consultant1 user. The password is redhat.

    [root@servera ~]# exit
    logout
    [student@servera ~]$ su - consultant1
    Password: redhat
    [consultant1@servera ~]$
  6. Navigate to the /home/consultants directory and create a file called consultant1.txt.

    1. Change to the /home/consultants directory.

      [consultant1@servera ~]$ cd /home/consultants
    2. Create an empty file called consultant1.txt.

      [consultant1@servera consultants]$ touch consultant1.txt
  7. List the default user and group ownership of the new file and its permissions.

    [consultant1@servera consultants]$ ls -l consultant1.txt
    -rw-rw-r--. 1 consultant1 consultant1 0 Mar  1 12:53 consultant1.txt
  8. Ensure that all members of the consultants group can edit the consultant1.txt file. Change the group ownership of the consultant1.txt file to consultants.

    1. Use the chown command to change the group ownership of the consultant1.txt file to consultants.

      [consultant1@servera consultants]$ chown :consultants consultant1.txt
    2. List the new ownership of the consultant1.txt file.

      [consultant1@servera consultants]$ ls -l consultant1.txt
      -rw-rw-r--. 1 consultant1 consultants 0 Mar  1 12:53 consultant1.txt
  9. Exit the shell and switch to the consultant2 user. The password is redhat.

    [consultant1@servera consultants]$ exit
    logout
    [student@servera ~]$ su - consultant2
    Password: redhat
    [consultant2@servera ~]$
  10. Navigate to the /home/consultants directory. Ensure that the consultant2 user can add content to the consultant1.txt file.

    1. Change to the /home/consultants directory. Add text to the consultant1.txt file.

      [consultant2@servera ~]$ cd /home/consultants/
      [consultant2@servera consultants]$ echo "text" >> consultant1.txt
    2. Verify that the text is present in the consultant1.txt file.

      [consultant2@servera consultants]$ cat consultant1.txt
      text
    3. Return to the workstation system as the student user.

      [consultant2@servera consultants]$ exit
      logout
      [student@servera ~]$ exit
      logout
      Connection to servera closed.
      [student@workstation ~]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish perms-cli

This concludes the section.

Revision: rh124-9.0-398f302