What I Wanted to Do
Understand and correctly set Linux file permissions.
What Are Permissions?
Permissions define who can do what with a file or directory.
-rwxr-xr-x
| Character | Meaning |
|---|---|
| r | Read (4) |
| w | Write (2) |
| x | Execute (1) |
| - | No permission (0) |
chmod: Change Permissions
Numeric mode
chmod 755 filename # rwxr-xr-x
chmod 644 filename # rw-r--r--
chmod 600 filename # rw-------
Common settings
755 → Web server directories
644 → Regular files
600 → SSH keys and config files
755 → Executable scripts
Symbolic mode
chmod +x script.sh # Add execute permission
chmod -x script.sh # Remove execute permission
chmod u+w file.txt # Add write for owner
chown: Change Owner
chown username filename
chown username:groupname filename
chown -R username directory # Recursive
Key Points
- SSH keys must be
chmod 600— SSH refuses connections otherwise - Never set web server files to 777 — it’s a security risk
- Be careful with
chmod -R— it changes everything recursively
Related Articles
Recommended Cloud Hosting
Looking for reliable cloud infrastructure? Check out these developer-friendly services.
- Cherry Servers - High-performance VPS and dedicated servers
- Cloudways - Managed cloud hosting for developers