Free Linux+ User and Group Permissions Questions and Answers — Questions and Answers
Question 1: A system administrator has set the umask value to `0027` for all users. What will the permissions be for a newly created directory?
- drwxr-xr-x
- drwxr-x--- (Correct answer)
- drw-r-----
- -rwxr-x---
Correct answer: drwxr-x---
The default base permission for a new directory is `777` (rwxrwxrwx). The umask value is subtracted from this base. `777 - 027 = 750`. A permission of `750` translates to `rwx` for the user (owner), `r-x` for the group, and no permissions for others, which is represented as `drwxr-x---`.
Question 2: An executable file has its permissions displayed as `-rwsr-xr-x`. What is the primary effect of the 's' in the user/owner permissions section?
- Any user who runs the file will have their primary group temporarily changed to the file's group.
- Only the file's owner and members of the root group can execute the file.
- The file will execute with the permissions of the file's owner, regardless of who runs it. (Correct answer)
- It indicates a 'secure' executable that cannot be modified by any user, including root.
Correct answer: The file will execute with the permissions of the file's owner, regardless of who runs it.
The 's' in the user/owner execute permission slot indicates that the setuid (SUID) bit is set. When a user executes a file with the SUID bit, the process runs with the privileges of the file's owner, not the user who launched it. This is commonly used for commands that need elevated (root) privileges to perform specific tasks, like `passwd`.
Question 3: A project manager wants to create a shared directory at `/srv/project_files`. Any new file or subdirectory created within this location must automatically be owned by the `developers` group. Which command will accomplish this?
- chmod u+s /srv/project_files
- chgrp developers /srv/project_files && chmod g+s /srv/project_files (Correct answer)
- chown :developers /srv/project_files && chmod +t /srv/project_files
- setfacl -m g:developers:rwx /srv/project_files
Correct answer: chgrp developers /srv/project_files && chmod g+s /srv/project_files
This requires two steps: first, setting the group owner of the directory to `developers` with `chgrp`, and second, setting the setgid (SGID) bit with `chmod g+s`. The SGID bit on a directory forces all new files and subdirectories created within it to inherit the group ownership of the parent directory.
Question 4: A user needs to change the ownership of a file named `report.txt` from the current user `alice` to the user `bob` and also change its group ownership to `editors`. Which of the following is the most efficient single command to achieve this?
- chown bob report.txt && chgrp editors report.txt
- chown bob:editors report.txt (Correct answer)
- setowner bob:editors report.txt
- chmod bob:editors report.txt
Correct answer: chown bob:editors report.txt
The `chown` command can change both the user and group owner in a single operation by using the `user:group` syntax. This is more efficient than running two separate commands (`chown` for the user and `chgrp` for the group).
Question 5: A system administrator is configuring a world-writable directory at `/var/shared/uploads`. To prevent users from deleting files they do not own, which permission should be set on the directory?
- setgid (2000)
- setuid (4000)
- read-only (0444)
- sticky bit (1000) (Correct answer)
Correct answer: sticky bit (1000)
The sticky bit is a special permission that, when set on a directory, allows users to delete or rename only the files they own, even if they have write permissions to the directory. This is commonly used on directories like `/tmp`. It can be set with `chmod +t` or by prepending a `1` to the octal permissions (e.g., `chmod 1777`).
Question 6: A user has a shell script `backup.sh` with permissions `-rw-r--r--`. When they try to execute it using `./backup.sh`, they receive a 'Permission denied' error. Which `chmod` command will grant the necessary permission with the least privilege required?
- chmod 755 backup.sh
- chmod a+x backup.sh
- chmod u+x backup.sh (Correct answer)
- chmod u+w backup.sh
Correct answer: chmod u+x backup.sh
The error occurs because the execute (x) permission is missing for the user (owner). The command `chmod u+x backup.sh` specifically adds the execute permission for the user owner, which is the most precise and secure way to fix the issue without granting unnecessary permissions to the group or others.
A system administrator has set the umask value to `0027` for all users.
What will the permissions be for a newly created directory?