Linux command list

chown command: change who owns a file

__ __ _ _____
\ \ / /__| |_|_ _|__ _ __ _ __ ___
\ \ /\ / / _ \ '_ \| |/ _ \ '__| '_ ` _ \
\ V V / __/ |_) | | __/ | | | | | |
\_/\_/ \___|_.__/|_|\___|_| |_| |_| |_
 
A sandbox for trying chown. Nothing here can touch your real files.
user@webterm:~/project$
 

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

Syntax

chown [options] owner[:group] file...

It changes who owns a file or directory.

Try it first

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.

Changing the owner

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.

Changing the group as well

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.

A whole directory

-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

When you actually reach for it

chown is what you type to hand over something you cannot touch because it is not yours.

SituationWhat to type
Take back a file created under sudosudo chown $USER:$USER config.yml
Hand a deployment to the web serversudo chown -R www-data:www-data /var/www/app
See who owns whatls -l
Change only the groupsudo chgrp <group> <file>

Things that trip people up

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.

Practise it hands-on

webterm.appthis site

  • Advanced Terminal Commands

    Learn commands for specific situations

    Try the tutorial

learn.webterm.appa separate site

>_WEBTERM LEARN

WebTerm Learn: from one command to actually using it

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

Related commands

chmod / ls / sudo / chgrp

Frequently asked questions

How is chown different from chmod?
`chmod` changes what may be done, `chown` changes whose it is. If you cannot write to a file, chmod is the answer when the permissions are wrong and chown is the answer when the file belongs to someone else.
Why does it need sudo?
Handing a file to another user is an administrative act, so only root may do it. Without `sudo` you get Operation not permitted.
What is the colon in user:user?
Owner on the left, group on the right. `chown user file` changes only the owner and leaves the group as it was, so write `user:user` when you want both.
After running something with sudo I can no longer edit my files.
That job left root-owned files behind. Check with `ls -l` and hand them back with `sudo chown <you>:<you> <file>`.
Anything to watch out for with -R?
The target. Running `-R` against `/` or `/home` rewrites ownership across the system and can leave the machine unable to boot.