Access Permissions   «Prev  Next»

chmod Change File Permissions

Changing permissions

Here are the steps you followed using the chmod command to change file permissions:
  1. You are currently logged in as user1, a user with normal permissions, and are in your home directory (/home/user1/). Obtain a listing of files in your home directory, including all associated permissions.
    Solution: Use the ls command with the –l argument.
  2. Note that you own a file named readme. As you can see, although you own the file, you do not have read permission for it. Using symbolic codes, change the permissions so you can read, as well as write and execute the file. Do not allow anyone else to read the file.
    Solution: chmod u+r readme
  3. Now you want to create a subdirectory of your home directory in which no one (including yourself, unless you take further steps) can create or delete files. You do, however, want to enable all users to list all directory contents. First, create the new subdirectory.
    Solution: mkdir subdir
  4. Using numeric codes, remove write permissions for all users.
    Solution: chmod 555 subdir
  5. Next, you want to create a new subdirectory of your home directory and then set permissions on this directory so no one, not even yourself, can list the files. However, you still want to allow all users to create and execute files, as long as they know where those files exist. To do this, create a directory named nolist.
    Solution: mkdir nolist
  6. Use the a argument of chmod to remove read privileges to the nolist directory for all users.
    Solution: chmod a-r nolist
  7. Set permissions so that no one but you can list the files. You still want other users to be able to create, delete, and execute new ones, however. Use numeric coding.
    Solution: chmod 733 nolist
  8. Now, switch to the user2 account.
    Solution: su user2
  9. Change to the nolist directory.
    Solution: cd nolist
  10. Type ls -l to list the files, subdirectories, and associated permissions for this directory.
  11. Note that you cannot list any files or subdirectories. However, you can create new files and subdirectories. Use touch to create a new file named testfile. Solution: touch testfile
  12. Create a new directory named testdir. Solution: mkdir testdir
  13. Now, suspend the user2 subshell and return to your login shell.
    Solution: suspend
  14. As user1, you have been tasked with creating a subdirectory inside your home directory that is completely hidden to all users. You are to make this directory so that no one can even discover its existence. First create a new subdirectory named temp. It should reside directly beneath your home directory (user1).
    Solution: mkdir temp
  15. Now, using numeric codes, set the permissions on this subdirectory so that only you can read, write, and execute files in the temp directory.
    Solution: chmod 700 temp
  16. Create a new subdirectory in the /home/user1/temp directory named hiddendir.
    Solution: mkdir ./temp/hiddendir
  17. Next, create a file in the hiddendir directory named hiddenfile.
    Solution: touch ./temp/hiddendir/hiddenfile
  18. Using numeric codes, change the permissions of the hiddendir directory to be consistent with the temp directory: only you can read, write, and execute files in the directory.
    Solution: chmod 700 ./temp/hiddendir
  19. Become user2 again.
    Solution: fg
  20. Go to the user1/temp directory. Be sure to enter the directory’s full path.
    Solution: cd /home/user1/temp
  21. Note that you cannot read the contents of this directory as user2. Go to the /home/user1 directory.
    Solution: cd /home/user1
  22. List the subdirectories, making sure to show all file attributes.
    Solution: ls -l
  23. As user2, you can see that the temp subdirectory exists, but you cannot list its contents. These contents include the hiddendir subdirectory. Both the subdir directory and its contents are effectively invisible. Exit the user2 subshell.
    Solution: exit