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

Audit identities, SSH access, and authentication-related state.

Query passwd database

Resolve user information through NSS.

bashLINUXgetentuseridentity
bash
getent passwd alice
Notes

Useful on systems backed by LDAP or other NSS sources.

Query group database

Resolve group entries through NSS.

bashLINUXgetentgroupidentity
bash
getent group docker
Notes

Useful when group data is not only in local `/etc/group`.

Lock user password

Disable password authentication for a user.

bashLINUXpasswdlocksecurity
bash
sudo passwd -l deploy
Notes

Useful during account offboarding or incident response.

Show password aging info

Inspect account password expiration details.

bashLINUXchagepasswordsecurity
bash
sudo chage -l alice
Notes

Useful for compliance and access reviews.

Safely edit sudoers

Open sudoers with syntax checking and locking.

bashLINUXsudovisudosecurity
bash
sudo visudo
Notes

Always use `visudo` instead of editing sudoers directly.

Test SSH daemon config

Validate SSH daemon configuration for syntax errors.

bashLINUXsshsshdconfig
bash
sudo sshd -t
Notes

Run before restarting SSH to avoid locking yourself out.

Install SSH public key manually

Append a key to authorized_keys.

bashLINUXsshkeysauth
bash
cat id_ed25519.pub >> ~/.ssh/authorized_keys
Notes

Ensure permissions on `~/.ssh` and `authorized_keys` are strict.

Permissions ACLs and Special Bits

Go beyond rwx with ACLs, sticky bit, and setuid/setgid.

Set sticky bit on shared directory

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

bashLINUXchmodsticky-bitpermissions
bash
chmod +t /shared/tmp
Notes

Common on world-writable directories like `/tmp`.

Set setgid on directory

Force new files to inherit the directory group.

bashLINUXchmodsetgidpermissions
bash
chmod g+s /srv/shared
Notes

Useful for team-shared directories.

Find setuid files

Search for files with the setuid bit set.

bashLINUXfindsetuidsecurity
bash
find / -perm -4000 -type f 2>/dev/null
Notes

Useful for security audits and hardening reviews.

Find world-writable paths

Audit files or directories writable by anyone.

bashLINUXfindpermissionssecurity
bash
find / -xdev -type d -perm -0002 2>/dev/null
Notes

Useful for security posture reviews.

Set default ACL on directory

Apply inherited ACL rules to new files and directories.

bashLINUXacldefaultpermissions
bash
setfacl -d -m g:appteam:rwx shared/
Notes

Useful in team collaboration directories.

SELinux and AppArmor Basics

Inspect and work with Linux mandatory access control frameworks.

Show SELinux mode

Print current SELinux mode.

bashLINUXselinuxsecuritymode
bash
getenforce
Notes

Common first step on SELinux-enabled hosts.

Show SELinux status

Display SELinux policy and mode details.

bashLINUXselinuxsecuritystatus
bash
sestatus
Notes

Provides more context than `getenforce`.

Restore SELinux contexts

Reset file labels according to policy.

bashLINUXselinuxrestoreconsecurity
bash
sudo restorecon -Rv /var/www/html
Notes

Very useful when copied files have wrong SELinux labels.

Allow service on custom SELinux port

Add or modify SELinux port context mapping.

bashLINUXselinuxportssecurity
bash
sudo semanage port -a -t http_port_t -p tcp 8080
Notes

Required when services move to nonstandard ports on SELinux systems.

Show AppArmor status

Display loaded AppArmor profiles.

bashLINUXapparmorsecuritystatus
bash
sudo aa-status
Notes

Useful on Ubuntu and other AppArmor-enabled systems.

Inspect recent audit messages

Query audit-related journal entries.

bashLINUXauditsecurityjournalctl
bash
journalctl -t audit --since '1 hour ago'
Notes

Helpful when security policy blocks access and you need clues quickly.