chown changes the owner and group of a file. Learn why it needs `sudo`, what the `user:user` form means, and how `-R` covers a whole directory, by running the commands in a real terminal in your browser.
Updated: 2026-09-06
chown [options] owner[:group] file...
It changes who owns a file or directory.
Start by seeing who owns what.
$ ls -l
total 16
drwxr-xr-x 2 root root 4096 Sep 6 00:57 build/
-rw-r--r-- 1 root root 11 Sep 6 00:57 config.yml
-rw-r--r-- 1 root root 16 Sep 6 00:57 deploy.log
-rw-r--r-- 1 user user 10 Sep 6 00:57 README.md
The third column is the owner and the fourth is the group.
Only README.md belongs to you; the rest belong to root.
That is what a job run under sudo leaves behind.
Try it directly and you are turned away.
$ chown user config.yml
chown: changing ownership of 'config.yml': Operation not permitted
Changing ownership is administrative, so it needs sudo.
$ sudo chown user config.yml
$ ls -l config.yml
-rw-r--r-- 1 user root 11 Sep 6 00:57 config.yml
The owner is now user, but the group is still root.
Anything after the : sets the group.
$ sudo chown user:user deploy.log
$ ls -l deploy.log
-rw-r--r-- 1 user user 16 Sep 6 00:57 deploy.log
The owner:group form is the safer habit.
Changing only one half is how files end up readable but not writable later on.
-R covers everything inside.
$ ls -l build
total 4
-rw-r--r-- 1 root root 15 Sep 6 00:57 bundle.js
$ sudo chown -R user:user build
$ ls -l build
total 4
-rw-r--r-- 1 user user 15 Sep 6 00:57 bundle.js
The directory itself changes too.
$ ls -l
total 16
drwxr-xr-x 2 user user 4096 Sep 6 00:57 build/
-rw-r--r-- 1 user root 11 Sep 6 00:57 config.yml
-rw-r--r-- 1 user user 16 Sep 6 00:57 deploy.log
-rw-r--r-- 1 user user 10 Sep 6 00:57 README.md
chown is what you type to hand over something you cannot touch because it is not yours.
| Situation | What to type |
|---|---|
| Take back a file created under sudo | sudo chown $USER:$USER config.yml |
| Hand a deployment to the web server | sudo chown -R www-data:www-data /var/www/app |
| See who owns what | ls -l |
| Change only the group | sudo chgrp <group> <file> |
When chmod does not help, look at the owner.
With -rw-r--r--, only the owner may write.
No amount of chmod will let you write to a file that is not yours, so read the third column of ls -l first.
The user has to exist.
$ sudo chown nosuchuser README.md
chown: invalid user: 'nosuchuser'
id <name> tells you whether an account is really there.
A mistyped file name stops it.
$ sudo chown user nope
chown: cannot access 'nope': No such file or directory
Check the target twice before using -R.
-R against / or /home rewrites ownership across the system.
Undoing that is painful, so always name the target explicitly.
webterm.appthis site
Advanced Terminal Commands
Learn commands for specific situations
learn.webterm.appa separate site

Commands stick when they show up in a real sequence of work, not one at a time. There is a course that builds them up in order.
See the course