What You'll Learn
Linux uses a permission system to control who can read, write, or execute files and directories. Understanding permissions is essential for security and troubleshooting "Permission denied" errors.
Reading Permission Strings
Run ls -l to see permissions:
-rw-r--r-- 1 alex alex 4096 Jan 15 notes.txt
drwxr-xr-x 2 alex alex 4096 Jan 15 documents/
The first column breaks down like this:
| Position | Meaning |
|---|---|
| Character 1 | Type: - = file, d = directory, l = symlink |
| Characters 2-4 | Owner permissions (the user who owns the file) |
| Characters 5-7 | Group permissions (users in the owning group) |
| Characters 8-10 | Others permissions (everyone else) |
Each set of three uses these letters:
r— Read: can view the file contents or list a directory.w— Write: can modify or delete the file, or add/remove files in a directory.x— Execute: can run the file as a program or enter a directory.
Changing Permissions with chmod
Numeric (Octal) Mode
Each permission has a number: read = 4, write = 2, execute = 1. Add them up:
chmod 755 script.sh # Owner: rwx (7), Group: r-x (5), Others: r-x (5)
chmod 600 secret.txt # Owner: rw- (6), Group: --- (0), Others: --- (0)
chmod 644 readme.md # Owner: rw- (6), Group: r-- (4), Others: r-- (4)
Symbolic Mode
chmod +x script.sh # Add execute permission for everyone
chmod u+w file.txt # Add write for the owner only
chmod o-rw file.txt # Remove read and write from others
Common Permission Patterns
| Mode | String | Use Case |
|---|---|---|
755 | rwxr-xr-x | Directories and executable scripts |
700 | rwx------ | Private directories (e.g., ~/.ssh) |
644 | rw-r--r-- | Regular files most users can read |
600 | rw------- | Sensitive files (SSH keys, passwords) |
Changing Ownership with chown
sudo chown alex:alex file.txt # Change owner and group
sudo chown -R www-data:www-data /var/www # Recursively change a web directory
Note: Only root (via sudo) can change ownership.
Practice Exercise
mkdir permissions-test
cd permissions-test
touch script.sh secret.txt readme.md
chmod 755 script.sh
chmod 600 secret.txt
chmod 644 readme.md
ls -la # See the permission differences
Troubleshooting
- "Permission denied" when running a script: Run
chmod +x script.sh. - "Permission denied" editing a system file: Use
sudo nano /etc/file.conf. - SSH key rejected: Check that
~/.ssh/id_rsais mode 600 and~/.ssh/is mode 700.
What's Next?
Now that you understand permissions, learn how to install and manage software:
Package Management for Beginners →