Linux Permissions and Security Cheat Sheet

High-value Linux permissions and security reference covering users, sudo, ACLs, special mode bits, SSH access, SELinux, and AppArmor basics.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Accounts Authentication and Access
Query passwd database
getent passwd alice

# Resolve user information through NSS.

Query group database
getent group docker

# Resolve group entries through NSS.

Lock user password
sudo passwd -l deploy

# Disable password authentication for a user.

Show password aging info
sudo chage -l alice

# Inspect account password expiration details.

Safely edit sudoers
sudo visudo

# Open sudoers with syntax checking and locking.

Test SSH daemon config
sudo sshd -t

# Validate SSH daemon configuration for syntax errors.

Install SSH public key manually
cat id_ed25519.pub >> ~/.ssh/authorized_keys

# Append a key to authorized_keys.

## Permissions ACLs and Special Bits
Set sticky bit on shared directory
chmod +t /shared/tmp

# Allow only owners to delete their own files in a shared directory.

Set setgid on directory
chmod g+s /srv/shared

# Force new files to inherit the directory group.

Find setuid files
find / -perm -4000 -type f 2>/dev/null

# Search for files with the setuid bit set.

Find world-writable paths
find / -xdev -type d -perm -0002 2>/dev/null

# Audit files or directories writable by anyone.

Set default ACL on directory
setfacl -d -m g:appteam:rwx shared/

# Apply inherited ACL rules to new files and directories.

## SELinux and AppArmor Basics
Show SELinux mode
getenforce

# Print current SELinux mode.

Show SELinux status
sestatus

# Display SELinux policy and mode details.

Restore SELinux contexts
sudo restorecon -Rv /var/www/html

# Reset file labels according to policy.

Allow service on custom SELinux port
sudo semanage port -a -t http_port_t -p tcp 8080

# Add or modify SELinux port context mapping.

Show AppArmor status
sudo aa-status

# Display loaded AppArmor profiles.

Inspect recent audit messages
journalctl -t audit --since '1 hour ago'

# Query audit-related journal entries.