nerdexam
LPI

010-160 · Question #24

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…

The correct answer is B. The execute bit should be set in the file's permissions. The 'Permission denied' error for ./test.sh occurs because the file lacks the execute bit; adding it with chmod makes the script runnable.

Security and File Permissions

Question

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?

Options

  • AThe file's extension should be changed from .sh to .bin.
  • BThe execute bit should be set in the file's permissions.
  • CThe user executing the script should be added to the exec group.
  • DThe SUID bit should be set in the file's permissions.
  • EThe script should be run using #!/test.sh instead of ./test.sh.

How the community answered

(44 responses)
  • A
    7% (3)
  • B
    89% (39)
  • C
    2% (1)
  • D
    2% (1)

Why each option

The 'Permission denied' error for ./test.sh occurs because the file lacks the execute bit; adding it with chmod makes the script runnable.

AThe file's extension should be changed from .sh to .bin.

Linux file executability is determined entirely by the execute permission bit, not by the filename extension; renaming .sh to .bin has no effect on permissions.

BThe execute bit should be set in the file's permissions.Correct

The listed permissions -rw-r--r-- show no execute bit is set for the owner, group, or others. Running 'chmod +x test.sh' adds the execute bit, which is the flag the Linux kernel checks before loading and running a file. Without the execute bit, the kernel rejects execution regardless of the file's valid script content.

CThe user executing the script should be added to the exec group.

The file's group 'exec' has only read permission as shown by -rw-r--r--, so joining that group does not grant execute rights; the execute bit itself must be set on the file.

DThe SUID bit should be set in the file's permissions.

The SUID bit causes a script to run with the file owner's effective UID, but it does not grant execute permission; the execute bit is still required before the kernel will run the file at all.

EThe script should be run using #!/test.sh instead of ./test.sh.

#!/test.sh is not a valid way to invoke a script from the command line; the shebang belongs on the first line inside the script file as the interpreter directive, not as a shell command.

Concept tested: Linux file execute permission bit and chmod

Source: https://man7.org/linux/man-pages/man1/chmod.1.html

Topics

#file permissions#execute bit#chmod#shell scripts

Community Discussion

No community discussion yet for this question.

Full 010-160 Practice