rh124_advanced_permissions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rh124_advanced_permissions [2026/10/23 09:17] – [Real vs effective ID] rpjdayrh124_advanced_permissions [2026/10/28 14:01] (current) – [SGID bit for directories] rpjday
Line 1: Line 1:
 ====== RH124 Advanced Permissions ====== ====== RH124 Advanced Permissions ======
 +
 +===== NOTE =====
 +
 +If you're running these commands as a non-root user, do not use the ''sudo'' command.
 +
 +===== Enterable but not readable directories =====
 +
 +<code>
 +$ chmod 0111 Poems
 +$ ls -ld Poems
 +$ ls Poems
 +$ cat Poems/twister
 +$ chmod 755 Poems
 +</code>
  
 ===== Strange permissions ===== ===== Strange permissions =====
Line 59: Line 73:
 ===== Setuid, Setgid and the sticky bit ===== ===== Setuid, Setgid and the sticky bit =====
  
-In addition to the three levels of "rwx" bits (octal 777), there are three more permission settings off to the left that are not obvious:+In addition to the three levels of "rwx" bits (octal 777), there are three more permission settings **off to the left** that are not obvious:
  
   * setuid bit (4)   * setuid bit (4)
Line 65: Line 79:
   * sticky bit (1)   * sticky bit (1)
  
-so a full octal representation for any file would be octal 7777 (regular settings are sometimes written 0755 or 0644 or whatever).+so a full octal representation for any file permissions would be octal 7777 (regular settings are sometimes written 0755 or 0644 or whatever).
  
-===== The setuid bit =====+===== The setuid bit for executable files =====
  
 This bit means that when you run this binary executable, it will **retain** its ownership: This bit means that when you run this binary executable, it will **retain** its ownership:
Line 110: Line 124:
 </code> </code>
  
-===== The setgid bit =====+===== The setgid bit for executable files =====
  
 No longer as popular but similar to above: No longer as popular but similar to above:
Line 123: Line 137:
  
 <code> <code>
-$ find /usr/bin -perm /2000 -exec ls -l {} \;+$ find /usr/bin -perm -2000 -exec ls -l {} \;
 -rwxr-sr-x. 1 root tty 24160 Jan 14  2026 /usr/bin/write -rwxr-sr-x. 1 root tty 24160 Jan 14  2026 /usr/bin/write
 $ $
Line 142: Line 156:
  
 **EXERCISE**: How would you identify all executables under ''/usr/bin'' with **either** setuid or setgid bits? **EXERCISE**: How would you identify all executables under ''/usr/bin'' with **either** setuid or setgid bits?
 +
 +===== The sticky bit (primarily for directories) =====
 +
 +You can see it set for certain directories:
 +
 +<code>
 +$ ls -ld /tmp
 +drwxrwxrwt. 10 root root 4096 Oct 23 04:54 /tmp
 +$
 +</code>
 +
 +It means that while anyone can copy content into that directory, only that owner or root can remove it.
 +
 +Find all directories with the sticky bit:
 +
 +<code>
 +$ sudo find / -type d -perm -1000
 +/dev/shm
 +/dev/mqueue
 +/sys/fs/bpf
 +/tmp
 +... snip ...
 +$
 +</code>
 +
 +<code>
 +$ ls -ld /dev/mqueue
 +drwxrwxrwt. 2 root root 40 Oct 23 02:00 /dev/mqueue
 +$
 +</code>
 +
 +Setting/unsetting the sticky bit:
 +
 +<code>
 +$ chmod +t <dirs>
 +$ chmod -t <dirs>
 +</code>
 +
 +===== SGID bit for directories =====
 +
 +This identifies directories such that, when new files or directories are created within that directory, they take on the same group affiliation of the directory itself, regardless of who does the creation.
 +
 +<code>
 +$ find / -type d -perm -2000 2> /dev/null
 +</code>
 +
 +How to add to a directory:
 +
 +<code>
 +$ chmod g+s <directory name>
 +</code>
 +
 +**NOTE**: There is no value for the SUID bit on directories.
 +===== Ask Google =====
 +
 +Google: Does EX200 exam ask about setuid and setgid and sticky bit?
 +
 +//"Yes, the Red Hat Certified System Administrator (RHCSA EX200) exam does cover special permissions, including setuid, setgid, and the sticky bit."//
 +
  • rh124_advanced_permissions.1792747023.txt.gz
  • Last modified: 2026/10/23 09:17
  • by rpjday