Skip to main content

Permissions Cheat Sheet

Understanding user management and file permissions is critical for security.

User and Group Management

CommandDescription
useradd -m -s /bin/bash johnCreate user 'john' with a home directory and bash shell.
usermod -aG sudo johnAdd 'john' to the 'sudo' group.
passwd johnChange password for 'john'.
groupadd adminsCreate a new group.

Octal Permissions Reference

  • 4 = Read (r)
  • 2 = Write (w)
  • 1 = Execute (x)
  • 0 = No permission (-)

Combine them:

  • 7 = rwx
  • 6 = rw-
  • 5 = r-x

Chmod Examples

CommandDescription
chmod 777 fileEveryone can read, write, and execute (Dangerous!).
chmod 755 dirOwner has full access, others can read/execute. Standard for directories.
chmod 644 fileOwner can read/write, others can read. Standard for files.
chmod 600 fileOnly owner can read/write. Standard for SSH keys.

Chown Examples

# Change owner to john
chown john file.txt

# Change owner and group
chown john:admins file.txt

# Recursively change owner of a directory
chown -R www-data:www-data /var/www/html