Chmod and Chown Commands in Ubuntu with Examples + Cheat Sheet

Share

chmod changes what users can do with a file, and chown changes who owns it. Both work the same on Ubuntu 26.04 LTS and Ubuntu 26.10. This guide explains how to read permissions, use numeric and symbolic modes, change owners and groups, and handle special bits, with copy-ready examples and a free cheat sheet.

Before You Start
Ubuntu version
Ubuntu 26.04 LTS or 26.10. chmod, chown and chgrp are part of the default install.
Permissions
You can chmod your own files. Changing the owner, or touching system files, needs sudo.
Be careful with -R
Never run recursive chmod or chown on /, /usr or /etc. It can make Ubuntu unbootable.
KEY TAKEAWAYS
01Read the letters
-rwxr-xr-- means owner rwx, group r-x, others r–.
02Numbers add up
r=4, w=2, x=1. So 7 is rwx, 6 is rw- and 5 is r-x.
03Common modes
644 for files, 755 for folders and scripts, 600 for private keys.
04Symbolic is safer
chmod u+x changes one bit and leaves the rest alone.
05Owner and group
sudo chown user:group file sets both in one command.
06Fix trees properly
Use find to give folders 755 and files 644 instead of chmod -R 777.
Free Cheat Sheet

Download the Ubuntu Chmod and Chown Commands Cheat Sheet

Every command from this guide on one printable sheet. Grab the PDF, or pick EPUB, DOCX, MOBI or AZW3 for your reader.

Also see Top 40 Linux commands for Ubuntu 26.04, Sudo command cheat sheet, Disk and partition commands in Ubuntu and UFW firewall commands in Ubuntu.

Read permissions first

Every file has an owner, a group and three sets of permissions: for the owner (u), the group (g) and everyone else (o).

1. List permissions

The first column shows the type and permissions, then the owner and group.

ls -l
ls -l
ls -ld ~/projects
ls -l sample output showing permissions on Ubuntu 26.04
Sample output: ls -l with owner, group and permission columns (illustrative).

2. Show numeric permissions

stat prints the mode as letters and as an octal number.

stat -c '%A %a %U:%G %n' notes.txt
stat -c '%A %a %U:%G %n' notes.txt

3. Check your user and groups

Group membership decides which group permissions apply to you.

id
id
groups

Chmod examples

chmod accepts symbolic modes such as u+x and numeric modes such as 755. Symbolic modes change only what you name. Numeric modes set every bit at once.

4. Make a script executable

Adds execute permission. u+x limits it to the owner.

chmod +x deploy.sh
chmod +x deploy.sh
chmod u+x deploy.sh
chmod -v u+x output on Ubuntu 26.04
Sample output: chmod -v reporting the old and new mode, then stat confirming it.

5. Add and remove with symbolic modes

Give the group write access and remove read access for others in one command.

chmod g+w,o-r notes.txt
chmod g+w,o-r notes.txt

6. Set a file to 644

Owner can read and write. Everyone else can only read. The usual mode for documents and web files.

chmod 644 notes.txt
chmod 644 notes.txt

7. Set a folder or script to 755

Owner has full access. Others can read and enter or run it.

chmod 755 deploy.sh
chmod 755 deploy.sh
chmod 755 ~/public

8. Protect private keys

SSH refuses keys that other users can read.

chmod 700 ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519

9. Change a tree recursively

Capital X adds execute only to folders and to files that are already executable.

chmod -R u+rwX,go+rX,go-w project/
chmod -R u+rwX,go+rX,go-w project/

10. Folders 755, files 644

find applies a different mode to each type, which is the clean way to fix a messy tree.

find project -type d -exec chmod 755 {} +
find project -type d -exec chmod 755 {} +
find project -type f -exec chmod 644 {} +

11. Copy permissions from another file

Matches the mode of a reference file.

chmod –reference=good.txt bad.txt
chmod --reference=good.txt bad.txt

12. Show what changed

-c reports only files whose mode changed. -v reports every file.

chmod -c 644 *.txt
chmod -c 644 *.txt

Chown and chgrp examples

Only root can give a file to another user, so chown almost always needs sudo.

13. Change the owner

Gives the file to the user alice.

sudo chown alice notes.txt
sudo chown alice notes.txt

14. Change owner and group

Sets both at once with user:group.

sudo chown alice:developers notes.txt
sudo chown alice:developers notes.txt

15. Change only the group

chgrp, or chown with a leading colon, changes just the group.

sudo chgrp developers notes.txt
sudo chgrp developers notes.txt
sudo chown :developers notes.txt

16. Take ownership of a folder tree

Fixes files created with sudo inside your home folder.

sudo chown -R "$USER":"$USER" ~/projects
sudo chown -R "$USER":"$USER" ~/projects

17. Find root-owned files in your home

Lists files that will give you Permission denied errors.

find ~ -user root
find ~ -user root

18. Change only matching owners

–from changes ownership only if the current owner matches.

sudo chown –from=root:root "$USER":"$USER" report.pdf
sudo chown --from=root:root "$USER":"$USER" report.pdf

19. Give a web server access

Ubuntu web servers run as www-data. Group ownership plus g+rwX lets you and the server both write, without making every file executable.

sudo chown -R "$USER":www-data /var/www/html
sudo chown -R "$USER":www-data /var/www/html
sudo chmod -R g+rwX /var/www/html

20. Add a user to a group

Group changes apply after the user logs out and back in.

sudo usermod -aG developers alice
sudo usermod -aG developers alice

Special bits, umask and ACLs

Special bits add a fourth digit in front of the normal mode, for example 2775.

21. Setgid on a shared folder

New files inherit the folder group, which keeps team folders consistent.

sudo chmod 2775 /srv/shared
sudo chmod 2775 /srv/shared
sudo chmod g+s /srv/shared

22. Sticky bit

Users can only delete their own files in the folder, as in /tmp.

sudo chmod +t /srv/shared
sudo chmod +t /srv/shared
ls -ld /tmp

23. Find setuid programs

Setuid programs run with the owner rights. Review this list when auditing a system.

find /usr/bin -perm -4000 -type f
find /usr/bin -perm -4000 -type f

24. Check and set the umask

umask removes bits from new files. The Ubuntu default 002 gives 664 files and 775 folders.

umask
umask
umask 027
umask output and default permissions on Ubuntu 26.04
Sample output: the default umask 0002 producing 664 files and 775 folders.

25. Grant one extra user with an ACL

ACLs add per-user rules on top of normal permissions. Install acl if setfacl is missing.

setfacl -m u:alice:rw report.txt
setfacl -m u:alice:rw report.txt
getfacl report.txt

Permission numbers quick reference

Mode Letters Typical use
777 rwxrwxrwx Avoid. Anyone can change or delete
775 rwxrwxr-x Shared team folders
755 rwxr-xr-x Folders, scripts and programs
700 rwx—— Private folders such as ~/.ssh
664 rw-rw-r– Shared team files
644 rw-r–r– Documents and web files
600 rw——- Private keys and secrets
400 r——– Read-only secrets

Tips and best practices

If something says Permission denied, check three things in order: who you are (id), who owns the file (ls -l), and whether every parent folder lets you in (ls -ld on each folder).

Avoid chmod 777 as a quick fix. It lets every user and every service change the file. Fix the owner or group instead.