This is the set of exercises following the article on Linux Permissions.
If you carefully read the article and understood the principles detailed inside, you should be able to answer most of the questions.
Should you find any errors or imprecisions, feel free to leave a comment.
Good luck!
Table of Contents
Linux Permissions Basics
Question 1 : connected as devconnected. Here is the output of my ls command.
Will I be able to write into the file some modifications?
Answer
Yes, the user has the read and write permissions. As a consequence, devconnected can perform some modifications on the file.
Question2 : connected as Bob (which is not part of the devconnected group). Here is the output of the ls command.
Bob wants to move my .profile (located in the devconnected folder) file to the root directory.
Will he be able to do it?
Answer
No! Bob belongs to the “others” category, which doesn’t have the write permission on the folder. As a consequence, he won’t be able to move the file.
Question3 : connected as Bob (still not part of the devconnected group). Here is the output of the ls command.
Bob wants to go into the devconnecteddirectory.
Can he do it?
Answer
No. Bob belongs to the “others” category, which doesn’t have the execute (going through) permission on the folder. Bob will be denied the access.
Question4 : connected as devconnected. Here is the output of the ls command.
Can I do it?
Answer
Yes! The write permission is set for the user. As a consequence, I will be able to write to this file.
Which file contains a list of users on a Linux system?
Answer
The passwd file located at /etc/passwd.
Binary Numeral System
Question 5 : Convert the binary number 1010001 to the decimal system.
Answer
81! From right to left, each number represents an increasing power of 2. If you add the numbers (except for zeros), it ends up at 81.
Question 6 : Convert the binary number 11011 to the decimal system.
Answer
27! From right to left, each number represents an increasing power of 2. If you add the numbers (except for zeros), it ends up at 27.
Question 7 : Convert the decimal number 12 to the binary numeral system.
Answer
1100! By applying multiple divisions to the number 12, and counting remainders on those operations, you end up with the binary number 1100
Chmod command
Question 8 : What permissions will the following command give : “chmod 777” ?
Answer
Setting permissions to 777 is equivalent to the following permissions : r w x r w x r w x so all permissions for all users.
Question 9 : What permissions will the following command give : “chmod 444” ?
Answer
Setting permissions to 444 is equivalent to the following permissions : r – – r – – r – – so read only for all users.
Question 10 : What permissions will the following command give : “chmod 641” ?
Answer
Setting permissions to 641 is equivalent to the following permissions : r w – r – – – – x so read-write the owner, r for the group and execute for the others.
Linux permission mask
Question 11 : what command should be executed to see the permission mask on Linux?
Answer
The permission mask can be seen using the umask command.
Question 12 : what is the role of the mask on Linux?
Answer
The Linux permission mask is a mask that sets the permissions for newly created files. Files are created with a 666 permission by default and directories are created with a 777 permission by default. The mask value is then deducted from this value to create the initial permissions.
Question 13 : Given this value for a mask, what permissions will be granted to files on my host?
Answer
The permissions for newly created files will be r w – r – – r – – (6 – 0 = 6, 6 – 2 = 4, 6 – 2 = 4)
Question 14 : given the same mask, what permissions will be granted to directories on my host?
Answer
The permissions for newly created directories will be r w x r – x r – x (7 – 0 = 7, 7 – 2 = 5, 7 – 2 = 5)
Directory permissions
Question 15 : what does it mean for a user to have the “execute” right on a directory?
Answer
It means that the user is able to go through the directory for navigation.
Question 16 : similarly, what does it mean for a user to have write permissions on a directory?
Answer
It means that the user is able to create and delete entries from this directory.
Question 17 : what is used on Linux to create share folders, allowing users to add files to a directory, but preventing them to delete entries that they don’t own?
Answer
It is called the sticky bit and it is used on Linux to create shared directories (for example the /tmp directory).
Question 18 : A file is set with the following permissions in a directory with the sticky bit activated. Will I be able to delete the file logged as “devconnected”?
Answer
No. If the sticky bit is activated, only the owner of the file will be able to delete this file (even if the other group has full permissions)
Question 19 : logged as john, will I be able to go through this directory? (john is not part of the devconnected group)
Answer
No. The sticky bit is a capital “T” meaning that the sticky bit is set for this directory but the execute permission is not set. As a consequence, no users except for the user itself can go through this directory.
Other commands
Question 20 : what command is used on Linux in order to change the owner of a file or directory?
Answer
It is the chown command. It should be directly followed by the new owner of the file and the name of the file we want to change.
Question 21 : what command is used on Linux in order to change the group of a file or directory?
Answer
It is the chgrp command. It is directly followed by the new group and by the file we want to apply the command on.
Question 22 : what option should be specified for the chgrp command to be apply recursively on directories and children?
Answer
To change groups recursively, you have to use the -R option for the chgrp command.
Question 23 : what option should be specified for the chgrp command to write all changes done to the standard output?
Answer
For the chgrp command to write all changes done, you should specify the -c option.
SUID & GUID
Question 24 : how would you shortly describe the SUID?
Answer
The SUID is used to execute a command as the owner of the file instead of the user that issued the command.
Question 25 : what popular command is executed on Linux with the SUID enabled?
Answer
The passwd command ie executed with the SUID enabled on Linux. It allows users to change their own passwords without being able to change other people password.
Question 26 : what command woul you run to set the SUID for a file on your host?
Answer
It is possible to set the SUID by executing “chmod u+s file” or “chmod 4777 file”
Question 27 : how would you shortly describe the GUID?
Answer
The GUID is used to execute a command as a member of the group owning the file instead of the group of the user who issued the command.
Question 28 : what command would you run to set the GUID for a file on your host?
Answer
It is possible to set the GUID by executing “chmod g+s file” or “chmod 2777 file”
Tricky Questions
Question 29 : if a directory with ” r w x r w x r w x” permissions is copied using the cp command, will the permissions be the same on the new directory ?
Answer
No. In order for the permissions to be preserved, you have to run cp with the -p option.
Question 30 : what is the difference between a lowercase “t” and an uppercase “T” for the sticky bit?
Answer
A lowercase t means that the sticky bit is set whereas an uppercase T means that the sticky bit is set but the execute permission is not set.
Answers for 19 and 30 are not right. Both T and t mean that sticky bit is set, but execute bit is unset in the first case, while it is set in the latter.
3 comments
Answers for 19 and 30 are not right. Both T and t mean that sticky bit is set, but execute bit is unset in the first case, while it is set in the latter.
[…] This article has an exercises article associated with it, read to train on the subject. […]
[…] 30 Linux Permissions Exercises for Sysadmins […]