Understanding File Permissions

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:

PositionMeaning
Character 1Type: - = file, d = directory, l = symlink
Characters 2-4Owner permissions (the user who owns the file)
Characters 5-7Group permissions (users in the owning group)
Characters 8-10Others permissions (everyone else)

Each set of three uses these letters:

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

ModeStringUse Case
755rwxr-xr-xDirectories and executable scripts
700rwx------Private directories (e.g., ~/.ssh)
644rw-r--r--Regular files most users can read
600rw-------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

What's Next?

Now that you understand permissions, learn how to install and manage software:

Package Management for Beginners →