DistributedNetworks DistributedNetworks


Access Permissions   «Prev  Next»

Changing File Ownership Groups

Here are the steps you need to follow to complete file and directory ownership.
  1. Log in to the system with the name user1 and the password userpass.
  2. Standard UNIX procedure is to create a home directory for each user. Once you log in, you are placed in your home directory, which is named user1 in this scenario. List the files in your home directory, showing the permissions, owner, and group of each file.
    Solution: Type ls -alg to list the files in the working directory and show their permissions, owners, and groups. The ls command without any options simply lists the files and directories. It does not give you detailed information about the permissions,owners, and groups associated with each file. The ls -l command does list most of the file attributes, but you need the a and g options to gain all the file and directory information.
  3. Notice that user1 owns the files and the /home/user1 directory and that root owns the /home directory. Notice also that a group, in this case user1, owns the files. This ownership is because, as you learned in the lesson, a file belongs to the user, as well as to that user’s group. Now, create an empty, new file named newfile inside your home directory (user1).
    Solution: Use the touch command to create a new, empty file. In addition to the command, you need to specify the name of the new, empty file you want to create.
  4. List the files in this directory again, showing the permissions, owner, and group of each file.
    Solution: Type ls –alg to list all attributes of the files in the working directory.
  5. Note that user1 owns newfile and that it belongs to the group to which user1 belongs. In this case the group is also named user1. Thisownership arrangement is just as you would expect. Now, assert root privileges.
    Solution: Use the su command to obtain root permissions.
  6. Create another new, empty file in this directory. Name this file newfile2. You are still in the user1 directory, because asserting root privileges and gaining a root subshell does not change your home directory.
    Solution: Use the touch command to create the newfile2 file.
  7. List the files in this directory, showing the permissions, owner, and group of each file.
    Solution: Type ls -alg to list all attributes of the files in the working directory.
  8. Notice that newfile2 has root as the owner. Also, notice that root is also the group. Now, change the ownership of newfile2 so that user1 is the owner.
    Solution: chown user1 newfile2
  9. Now, change the group ownership of newfile2 so it belongs to the same group as the other files in this directory.
    Solution: chgrp user1 newfile2
  10. List the files in this directory to confirm that your changes in ownership and group have taken effect.
    Solution: ls -alg
  11. You have changed the ownership and the group associated with newfile2. Now, create a subdirectory to the user1 directory. Name it newdir.
    Solution: mkdir newdir
  12. Without changing directories, create a new, empty file named newfile3 in the newdir subdirectory. Use ./ to indicate the current directory.
    Solution: touch ./newdir/newfile3
  13. Now, change the ownership of the newdir subdirectory and its contents so user1 is the owner.
    Solution: chown -R user1 ./newdir
  14. Close the root subshell.
    Solution: To surrender root permissions and/or close a subshell, type the exit command.
  15. Now, change the ownership of newfile2 so that user2 is the owner.
    Solution: chown user2 newfile2