Bird
Raised Fist0
Linux CLIscripting~20 mins

Special permissions (setuid, setgid, sticky bit) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Special Permissions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
What is the output of ls -l for a file with setuid bit set?
You run ls -l on a file with the setuid bit set. Which of the following shows the correct permission string for that file?
Linux CLI
ls -l /path/to/setuid_file
A-rwsr-xr-x 1 user group 1234 Apr 27 12:00 setuid_file
B-rwxr-sr-x 1 user group 1234 Apr 27 12:00 setuid_file
C-rwxr-xr-t 1 user group 1234 Apr 27 12:00 setuid_file
D-rwxr-xr-x 1 user group 1234 Apr 27 12:00 setuid_file
Attempts:
2 left
💡 Hint
Look for an 's' in the user execute position to indicate setuid.
💻 Command Output
intermediate
1:30remaining
What does the sticky bit do on a directory?
You set the sticky bit on a directory. What effect does it have on the directory's behavior?
Linux CLI
chmod +t /tmp/shared_dir
ls -ld /tmp/shared_dir
AOnly the directory owner, file owner, or root can delete or rename files inside the directory.
BAll users can delete or rename any files inside the directory regardless of ownership.
CThe directory becomes read-only for all users except root.
DThe directory allows execution of files inside it by all users.
Attempts:
2 left
💡 Hint
Think about shared directories like /tmp where many users write files.
📝 Syntax
advanced
1:30remaining
Which chmod command sets the setgid bit on a directory?
You want to set the setgid bit on a directory named project. Which command correctly does this?
Achmod o+s project
Bchmod +s project
Cchmod g+s project
Dchmod u+s project
Attempts:
2 left
💡 Hint
The setgid bit is related to the group permissions.
🚀 Application
advanced
1:30remaining
What is the effect of setgid on a directory's new files?
You set the setgid bit on a directory. What happens to the group ownership of new files created inside that directory?
ANew files inherit the user's primary group, ignoring the directory's group.
BNew files inherit the group ownership of the directory, not the user's primary group.
CNew files have no group ownership set.
DNew files inherit the group ownership of the parent directory's parent.
Attempts:
2 left
💡 Hint
Think about how group collaboration is managed in shared directories.
🧠 Conceptual
expert
1:30remaining
What error occurs if a non-root user tries to set the setuid bit on a file they own?
A user tries to run chmod u+s myscript.sh on a file they own but is not root. What happens?
Linux CLI
chmod u+s myscript.sh
AFile becomes unreadable due to permission conflict.
BThe setuid bit is set successfully without errors.
CSyntax error because setuid bit cannot be set with chmod.
DPermission denied error because only root can set setuid bit.
Attempts:
2 left
💡 Hint
Consider who has the privilege to set special permission bits.

Practice

(1/5)
1. What does the setuid permission do on an executable file?
easy
A. Runs the program with the file owner's permissions
B. Allows anyone to delete the file
C. Makes new files inherit the folder's group
D. Prevents the file from being executed

Solution

  1. Step 1: Understand setuid purpose

    The setuid permission allows a program to run with the permissions of the file owner, not the user running it.
  2. Step 2: Compare options with setuid behavior

    Only Runs the program with the file owner's permissions correctly describes this behavior; others describe different permissions or incorrect effects.
  3. Final Answer:

    Runs the program with the file owner's permissions -> Option A
  4. Quick Check:

    setuid = runs as owner [OK]
Hint: Setuid means run as file owner, not current user [OK]
Common Mistakes:
  • Confusing setuid with sticky bit
  • Thinking setuid changes file deletion rights
  • Mixing setuid with setgid effects
2. Which command correctly sets the setgid bit on a directory named shared?
easy
A. chmod g+s shared
B. chmod +s shared
C. chmod u+s shared
D. chmod o+s shared

Solution

  1. Step 1: Identify correct chmod syntax for setgid

    The setgid bit is set using g+s with chmod on directories.
  2. Step 2: Verify options

    chmod g+s shared uses chmod g+s shared, which is correct. Other options use incorrect flags or users.
  3. Final Answer:

    chmod g+s shared -> Option A
  4. Quick Check:

    Setgid = chmod g+s [OK]
Hint: Setgid uses 'g+s' with chmod on directories [OK]
Common Mistakes:
  • Using '+s' without user class
  • Confusing setuid (u+s) with setgid
  • Trying to set setgid on files with wrong syntax
3. Given a directory /tmp/shared with permissions drwxrwxrwt, what does the t at the end signify?
medium
A. Setuid bit is set
B. Sticky bit is set
C. Setgid bit is set
D. No special permissions set

Solution

  1. Step 1: Interpret permission string ending with 't'

    The 't' at the end of directory permissions indicates the sticky bit is set.
  2. Step 2: Match 't' with sticky bit meaning

    The sticky bit prevents users from deleting files they don't own in that directory.
  3. Final Answer:

    Sticky bit is set -> Option B
  4. Quick Check:

    't' at end = sticky bit [OK]
Hint: 't' at end of permissions means sticky bit set [OK]
Common Mistakes:
  • Confusing 't' with setuid or setgid
  • Thinking 't' means no special permission
  • Misreading permissions string
4. You set the setuid bit on a script using chmod u+s script.sh, but it doesn't run with owner permissions. What is the likely problem?
medium
A. You need to set the sticky bit instead
B. The file owner must be root for setuid to work
C. The script is a shell script and setuid does not work on scripts
D. You forgot to set execute permission

Solution

  1. Step 1: Understand setuid behavior on scripts

    Most Linux systems ignore setuid on shell scripts for security reasons.
  2. Step 2: Evaluate other options

    Sticky bit is unrelated, owner need not be root, and execute permission is usually set if script runs.
  3. Final Answer:

    The script is a shell script and setuid does not work on scripts -> Option C
  4. Quick Check:

    Setuid ignored on scripts [OK]
Hint: Setuid rarely works on scripts, only on binaries [OK]
Common Mistakes:
  • Assuming setuid works on all files
  • Confusing sticky bit with setuid
  • Not checking execute permission
5. You want to create a shared directory /data/shared where all files created inside inherit the directory's group and users cannot delete others' files. Which commands set this up correctly?
hard
A. chmod 2777 /data/shared && chmod g+s /data/shared
B. chmod 777 /data/shared && chmod g+s /data/shared
C. chmod 2777 /data/shared
D. chmod 2777 /data/shared && chmod +t /data/shared

Solution

  1. Step 1: Set setgid and sticky bit on directory

    Setgid (2) makes new files inherit group; sticky bit (1) prevents deleting others' files.
  2. Step 2: Analyze commands

    chmod 2777 /data/shared && chmod +t /data/shared sets permissions to 2777 (setgid + rwxrwxrwx) and adds sticky bit with chmod +t. This correctly applies both.
  3. Final Answer:

    chmod 2777 /data/shared && chmod +t /data/shared -> Option D
  4. Quick Check:

    Setgid + sticky bit = chmod 2777 + t [OK]
Hint: Setgid=2xxx, sticky=1xxx; combine for shared dir [OK]
Common Mistakes:
  • Using sticky bit without setgid
  • Confusing octal codes for permissions
  • Setting wrong permission order
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard