Linux Permissions 2 — Questions and Answers
Question 1: What does the sticky bit do when set on a directory?
- Prevents users from deleting files they do not own (Correct answer)
- Makes the directory read-only for all users
- Allows any user to write files into the directory
- Hides the directory from directory listings
Correct answer: Prevents users from deleting files they do not own
The sticky bit on a directory restricts file deletion so only the file owner, directory owner, or root can remove files.
Question 2: Which octal value represents rwxr-x--- for a file?
- 754
- 755
- 750 (Correct answer)
- 740
Correct answer: 750
rwx=7 for owner, r-x=5 for group, ---=0 for others gives octal 750.
Question 3: What is the effect of the setgid bit on a directory?
- New files inherit the directory's group ownership (Correct answer)
- New files are owned by the user who created them
- The directory can only be accessed by the group
- Group members get execute permission automatically
Correct answer: New files inherit the directory's group ownership
When setgid is set on a directory, newly created files and subdirectories inherit the directory's group rather than the creator's primary group.
Question 4: A file has permissions -rw-rw-r--. What is the umask that likely produced this from a default of 666?
- 002 (Correct answer)
- 022
- 006
- 033
Correct answer: 002
A umask of 002 subtracts write permission from others (666 - 002 = 664, i.e., rw-rw-r--).
Question 5: Which command changes the group ownership of a file to 'devs'?
- chgrp devs file.txt
- chown :devs file.txt
- chmod g=devs file.txt
- Both A and B (Correct answer)
Correct answer: Both A and B
Both `chgrp devs file.txt` and `chown :devs file.txt` correctly change the group ownership of a file.
Question 6: What does the execute permission on a directory allow a user to do?
- Enter the directory and access its contents (Correct answer)
- List the files inside the directory
- Create new files inside the directory
- Run scripts stored in the directory
Correct answer: Enter the directory and access its contents
Execute permission on a directory (also called search permission) allows users to traverse into it and access files if they know the names.
Question 7: How would you add write permission for the group on a file using symbolic mode?
- chmod g+w file.txt (Correct answer)
- chmod +gw file.txt
- chmod g=w file.txt
- chmod 020 file.txt
Correct answer: chmod g+w file.txt
The symbolic syntax `chmod g+w file.txt` adds write permission for the group without affecting other permissions.
What does the sticky bit do when set on a directory?