How to Change File Permissions on Linux
Understand Linux file permissions and learn to use chmod and chown to control who can read, write, and execute files on your system.
How Linux Permissions Work
Every file on Linux has an owner, a group, and three sets of permissions: one for the owner, one for the group, and one for everyone else (other). Run ls -l to see them:
-rwxr-xr-- 1 alice devs 4096 Jun 1 10:00 deploy.sh
The permission string -rwxr-xr-- breaks down as:
-— file type (- = file, d = directory, l = symlink)rwx— owner can read, write, executer-x— group can read and execute, not writer--— others can only read
chmod — Change Permissions
You can set permissions with symbolic or numeric (octal) notation.
Symbolic notation
chmod +x script.sh # add execute for everyone
chmod u+w file.txt # add write for the owner
chmod go-w secret.txt # remove write from group and others
chmod a+r public.html # add read for all
Letters: u=owner, g=group, o=others, a=all. Operators: + add, - remove, = set exactly.
Numeric (octal) notation
Each permission is a number: read=4, write=2, execute=1. Add them for each group:
chmod 755 deploy.sh # owner: rwx (7), group: r-x (5), others: r-x (5)
chmod 644 config.txt # owner: rw- (6), group: r-- (4), others: r-- (4)
chmod 600 id_rsa # owner: rw- (6), group: none (0), others: none (0)
Common patterns to memorise:
- 755 — executable script (owner full control, others read/execute)
- 644 — regular file (owner read/write, others read-only)
- 600 — private file like SSH keys (owner only)
- 777 — everyone full access (avoid in production)
Recursive permissions
chmod -R 755 /var/www/html # set 755 on all files in directory
chown — Change Owner and Group
chown alice file.txt # change owner to alice
chown alice:devs file.txt # change owner and group
chown -R www-data /var/www/html # recursive ownership change
sudo chown root /etc/sudoers # system files need sudo
Practical Examples
# Make a script executable and run it
chmod +x ~/scripts/backup.sh
~/scripts/backup.sh
# Fix a web server's document root
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
# Lock down an SSH private key
chmod 600 ~/.ssh/id_ed25519