010-160 practice question 7 of 15

The current directory contains the following file: -rw-r—r— 1 root exec 24551 Apr 2 12:36 test.sh The file contains a valid shell script, but executing this file using ./test.sh leads to this error: bash: ./test.sh: Permission denied What should be done in order to successfully execute the script?

Full set: 81 questions
Answer options
A: The file’s extension should be changed from .sh to .bin.
B: The execute bit should be set in the file’s permissions. Correct answer
C: The user executing the script should be added to the exec group.
D: The SetUID bit should be set in the file’s permissions
E: The script should be run using #!./test. sh instead of ./test.sh.
Correct Answer:
B. The execute bit should be set in the file’s permissions.
Explanation

The file's permissions are -rw-r--r--. The x (execute) bit is not set for the owner, the group, or other users. In Linux, to execute a file directly (e.g., ./test.sh), the file must have the execute permission enabled for the user attempting to run it. The error Permission denied is the direct result of this missing permission. Adding the execute bit, for example with the command chmod +x test.sh, will grant the necessary permission and allow the script to be run.

Why Incorrect

A. File extensions in Linux are primarily for user convenience and do not determine a file's executability; the permission bits do.
C. The exec group only has read permission (r--). Adding a user to this group would not grant the required execute permission.
D. The SetUID bit only works on files that are already executable. It cannot grant executability on its own.
E. The #! (shebang) is a directive used on the first line inside a script file to specify its interpreter, not as part of the command to run it.

References

1. GNU Coreutils Manual, chmod command: "The letters rwxXst select file mode bits for the affected users: read (r), write (w), execute (or search for directories) (x)..." This document confirms that the 'x' bit is required for execution.

Source: GNU Coreutils, Section 11.1, "chmod: Change file modes".

2. The Linux man-pages project, chmod(1): "The operator + causes the selected file mode bits to be added to the existing file mode bits of each file". This explains the mechanism for adding the execute bit.

Source: chmod(1) Linux manual page, section DESCRIPTION.

3. University of California, Berkeley, EECS Courseware: In lectures on file systems, it is established that the execute permission bit must be set for a file to be executed as a program. The absence of this bit prevents the kernel's execve() system call from succeeding, resulting in a permission error.

Source: UC Berkeley, EECS Department, CS 162: Operating Systems and Systems Programming, Lecture 12: File Systems.

Scroll to Top