File permissions control who can read, write, and execute files on your server.
Permission Format
-rwxr-xr-- 1 owner group 4096 Jan 1 12:00 file.txtThe permission string breaks down as:
- r = read (4)
- w = write (2)
- x = execute (1)
Three groups: owner, group, others.
Changing Permissions
# Using numbers
chmod 755 file.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 secrets # rw-------
# Using letters
chmod u+x script.sh # Add execute for owner
chmod go-w file.txt # Remove write for group/others
chmod -R 755 /var/www # RecursiveChanging Ownership
chown user:group file
chown -R www-data:www-data /var/wwwCommon Permission Patterns
- 755 — directories, scripts
- 644 — regular files
- 600 — sensitive files (SSH keys, configs with passwords)
- 700 — private directories