220-1102 Question 240
Single answerchmodA junior technician copied a shell script named backup.sh to a Linux workstation. When the user tries to run it with ./backup.sh, the system returns: Permission denied. Running ls -l backup.sh shows: -rw-r--r-- 1 user user 2048 backup.sh. The user should be able to run the script, but only the file owner should be allowed to modify it. Which command should the technician use to fix the permissions?
- A
chmod 755 backup.sh
- B
chmod 744 backup.sh
- C
chmod 644 backup.sh
- D
chmod +x backup.sh
Show answer and explanation
Correct answer: B
Explanation
The file currently has permissions -rw-r--r--, which corresponds to 644: the owner can read and write, while group and others can only read. Because execute permission is missing, running the script directly with ./backup.sh fails. To allow execution, the owner needs the execute bit set. The best answer is chmod 744 backup.sh, which results in rwxr--r--. This allows the owner to read, write, and execute the script while preventing group and others from modifying it. Although chmod 755 would also make the script executable and still restrict write access to the owner, it unnecessarily grants execute permission to group and others. In real-world support and security practice, technicians should follow the principle of least privilege and assign only the permissions required. Standard Linux file permission behavior is documented in the chmod and file permissions sections of common Linux manual pages, such as man chmod.
- A. Incorrect.
Incorrect. chmod 755 sets permissions to rwxr-xr-x. This would allow the owner to read, write, and execute the script, but it would also give execute permission to group and others. The scenario only states that the user should be able to run the script and that only the owner should be allowed to modify it. While 755 does satisfy the owner-only modification requirement, it grants broader execute access than necessary, making it a less appropriate choice under the principle of least privilege.
- B. Correct.
Correct. chmod 744 sets permissions to rwxr--r--. The owner gets read, write, and execute permissions, which allows the script to be run and edited by the owner. Group and others get read-only access, so they cannot modify the file. This directly matches the requirement that the user can run the script while only the owner can modify it.
- C. Incorrect.
Incorrect. chmod 644 sets permissions to rw-r--r--. This keeps the file non-executable for everyone, including the owner. The original problem is that ./backup.sh fails due to missing execute permission, so 644 would not solve the issue.
- D. Incorrect.
Incorrect. chmod +x backup.sh adds execute permission for owner, group, and others based on the current umask and existing mode behavior, often resulting in the file becoming executable more broadly than required. While this may allow the script to run, it does not explicitly set the precise permission set requested in the scenario. A technician choosing this may be thinking only about making the script executable, not about assigning the most appropriate final permissions.