File Permissions & Ownership
File permission modes, ownership management, access control lists, and special permission bits.
Numeric (Octal) Permissions
chmod 640 /etc/myapp.conf
755 rwxr-xr-x Executables, directories 644 rw-r--r-- Regular files, configs 600 rw------- Private keys, secrets 700 rwx------ Private directories, .ssh/ 750 rwxr-x--- Group-shared executables 664 rw-rw-r-- Group-collaborative files
chmod -R 755 /var/www/html/
-R 755 makes all files executable. For web directories, set directories to 755 and files to 644 separately.
|
find /var/www/html -type d -exec chmod 755 {} \;
find /var/www/html -type f -exec chmod 644 {} \;
Symbolic Permissions
chmod u+x script.sh
chmod go-w /etc/important.conf
chmod u=rwx,g=rx,o= /opt/app/
chmod a+r /tmp/shared-file
Ownership
sudo chown jdoe /opt/app/config.yml
sudo chown jdoe:developers /opt/app/
sudo chgrp developers /opt/app/
sudo chown -R jdoe:developers /opt/app/
Umask
umask
0022
Default file creation: 666 - 022 = 644 (rw-r—r--). Default directory: 777 - 022 = 755 (rwxr-xr-x).
umask 077
umask 027
touch /tmp/test-umask
ls -l /tmp/test-umask
-rw-r----- 1 evan evan 0 Apr 10 10:00 /tmp/test-umask
Persistent umask: set in ~/.bashrc (per-user) or /etc/profile.d/umask.sh (system-wide).
Special Permissions
chmod u+s /usr/local/bin/special-app
chmod 4755 /usr/local/bin/special-app
passwd uses SUID to write to /etc/shadow as root. SUID on a directory has no effect.
chmod g+s /usr/local/bin/group-app
chmod 2755 /usr/local/bin/group-app
chmod g+s /opt/shared-project/
This is the RHCSA-critical one. Without SGID, new files get the creator’s primary group. With SGID, they inherit the directory’s group — essential for team collaboration.
chmod +t /opt/shared-drop/
chmod 1777 /opt/shared-drop/
/tmp has the sticky bit. Without it, any user could delete any other user’s temp files.
ls -ld /tmp /usr/bin/passwd
drwxrwxrwt 24 root root 4096 Apr 10 10:00 /tmp -rwsr-xr-x 1 root root 59976 Apr 10 10:00 /usr/bin/passwd
Lowercase s/t = special + execute. Uppercase S/T = special without execute (usually a mistake).
find / -type f -perm -4000 -ls 2>/dev/null
find / -type f -perm -2000 -ls 2>/dev/null
ACLs — Access Control Lists
Standard permissions only allow one owner and one group. ACLs let you grant access to additional users and groups.
getfacl /opt/shared/report.txt
# file: opt/shared/report.txt # owner: jdoe # group: developers user::rw- user:analyst:r-- group::rw- group:auditors:r-- mask::rw- other::---
setfacl -m u:analyst:r /opt/shared/report.txt
setfacl -m g:auditors:rw /opt/shared/report.txt
setfacl -x u:analyst /opt/shared/report.txt
setfacl -b /opt/shared/report.txt
setfacl -m d:g:developers:rwx /opt/shared/
setfacl -R -m g:developers:rwx /opt/shared/
+ sign in ls -l output indicates ACLs are presentls -l /opt/shared/report.txt
-rw-rw----+ 1 jdoe developers 1024 Apr 10 10:00 /opt/shared/report.txt
RHCSA Collaboration Directory Pattern
This combines SGID, default ACLs, and group ownership — a common exam scenario.
# Create directory owned by the team group
sudo mkdir /opt/team-project
sudo chown :developers /opt/team-project
# SGID — new files inherit group
sudo chmod 2770 /opt/team-project
# Default ACL — new files are group-writable
sudo setfacl -m d:g:developers:rwx /opt/team-project
# Verify
ls -ld /opt/team-project
getfacl /opt/team-project