Linux / Bash
Beginner
1 min read
Understanding Linux File Permissions
Example
# View file permissions
ls -l /etc/passwd
# -rw-r--r-- 1 root root 2847 Apr 1 10:00 /etc/passwd
# ^ ^ ^ ^
# type+perms links owner group
# View permissions in octal
stat -c "%a %n" /etc/passwd
# 644 /etc/passwd
# Permission bit reference:
# r = 4, w = 2, x = 1
# rwx = 7 | rw- = 6 | r-x = 5 | r-- = 4 | -wx = 3 | -w- = 2 | --x = 1 | --- = 0
# Common permission patterns:
# 644 (-rw-r--r--) regular files
# 755 (drwxr-xr-x) directories & executables
# 600 (-rw-------) private keys, sensitive files
# 700 (drwx------) private directories
# 777 (drwxrwxrwx) world-writable (avoid in production)
# Check permissions on several files
ls -l /etc/shadow /etc/sudoers /etc/ssh/ssh_host_rsa_key
# ---------- 1 root shadow ... /etc/shadow
# -r--r----- 1 root root ... /etc/sudoers
# ---------- 1 root root ... /etc/ssh/ssh_host_rsa_key
# Display all files in a dir with permissions
ls -la /etc/ | head -20
# Find world-writable files (security audit)
find /var/www -perm -002 -type f
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash