Linux Exercise: Permissions

Default permissions

  1. Check the current value of your umask.
    • $ umask
  2. Set your umask to 000. Create a directory "dir1" and a file "file1". What are their permissions?
    • $ umask 000
    • $ mkdir dir1
    • $ touch file1
    • $ ls -l
      The permissions will be rwxrwxrwx and rw-rw-rw-, respectively.
  3. Set your umask to 022. Create a directory "dir2" and a file "file2". What are their permissions?
    • $ umask 022
    • $ mkdir dir2
    • $ touch file2
    • $ ls -l
      The permissions will be rwxr-xr-x and rw-r--r--, respectively.
  4. Set your umask to 077. Create a directory "dir3" and a file "file3". What are their permissions?
    • $ umask 077
    • $ mkdir dir3
    • $ touch file3
    • $ ls -l
      The permissions will be rwx------ and rw-------, respectively.

Working with permissions

This part of the exercise will require you to work with a partner who is logged into the same Linux system. If you don't have a partner who is logged into the same Linux system, then you can setup an additional user account and then use a separate SSH session to login as that user. You can then test your work from this second user account.

The objective of this exercise is to setup three directories in your home directory:

  • The directory "private" contains private content and should not be accessible for others at all.
  • The directory "public" contains public content and should be readable for others. However, the only person with write permission should be you.
  • The directory "incoming" is used for incoming data: It should be world-writeable.
  1. In your home directory, create the directory "private" with the proper permissions.
    • $ mkdir private
    • $ chmod 700 private
  2. In your "private" directory, create a file "privatefile".
    • $ touch private/privatefile
  3. In your home directory, create the directory "public" with the proper permissions.
    • $ mkdir public
    • $ chmod 755 public
  4. In your "public" directory, create a file "publicfile". Make sure this file has the proper permissions so that you can edit the file, but others can only read it.
    • $ touch public/publicfile
    • $ chmod 644 public/publicfile
  5. In your home directory, create the directory "incoming" with the proper permissions.
    • $ mkdir incoming
    • $ chmod 777 incoming
  6. Wait for your lab partner to arrive at this same stage. Once your partner is ready, try to access each others home directory, and the directories within? Does this work?
    • $ cd /home/partner
  7. Take a look at the permissions on your home directory itself, and fix these. Then notify your lab partner so that he or she can try to access your home directory again.
    • $ ls -ld ~
      The permissions on your home directory are rwx------ by default. For this reason your lab partner does not have access to your home directory at all. That access is required to descend into subdirectories in your home directory.
    • $ chmod 755 ~
  8. Once again try to access your partners home directory, and the directories within? Does this work?
    • $ cd /home/partner
    • $ cd private
    • $ cd public
    • $ cat publifile
    • $ cd ../incoming
    • $ touch myfile
End of exercise