Linux chown Command
last modified October 23, 2026
The chown (change owner) command in Linux changes the user and
group ownership of files and directories. Ownership determines which set of
permission bits applies to a user: those of the owner, the group, or
others.
Changing the owner of a file requires root privileges, so most examples use
sudo. The owner of a file may change its group to any group they
are a member of. The related chgrp command changes only the
group. The examples use GNU chown from coreutils, the user
jano, who belongs to the devs group, and another
user alice.
Changing the owner
In its simplest form, chown takes a user name and a file.
sudo chown alice report.txt
The third column of ls -l shows the owner and the fourth the
group. The owner changed to alice; the group stays the same.
$ ls -l report.txt -rw-r--r-- 1 jano jano 2 Oct 23 09:00 report.txt $ sudo chown alice report.txt $ ls -l report.txt -rw-r--r-- 1 alice jano 2 Oct 23 09:00 report.txt
Changing the owner and group
The form user:group changes both at once.
sudo chown alice:devs data.csv sudo chown alice: config.ini
With a colon and no group name, the group is set to the login group of the
user, here the alice group.
$ sudo chown alice:devs data.csv $ ls -l data.csv -rw-r--r-- 1 alice devs 2 Oct 23 09:00 data.csv $ sudo chown alice: config.ini $ ls -l config.ini -rw-r--r-- 1 alice alice 2 Oct 23 09:00 config.ini
Changing only the group
The form :group changes only the group, which is what
chgrp does as well.
chown :devs notes.txt chgrp devs old.txt
No sudo is needed: we own the files and we are a member of the
devs group, as the groups command shows.
$ groups jano devs $ chown :devs notes.txt $ chgrp devs old.txt $ ls -l notes.txt old.txt -rw-r--r-- 1 jano devs 2 Oct 23 09:00 notes.txt -rw-r--r-- 1 jano devs 2 Oct 23 09:00 old.txt
Numeric IDs
Users and groups can be given by their numeric IDs.
sudo chown 1001:1001 old.txt sudo chown 2000:2000 notes.txt
User ID 1001 is alice, but group ID 1001 belongs to
devs; user and group IDs are independent numbers. IDs without
an account, such as 2000, are accepted and shown as numbers by
ls -l. This happens with files extracted from archives or copied
from other systems. The -n option of ls always
shows numeric IDs.
$ id alice uid=1001(alice) gid=1002(alice) groups=1002(alice) $ sudo chown 1001:1001 old.txt $ sudo chown 2000:2000 notes.txt $ ls -ln old.txt notes.txt -rw-r--r-- 1 2000 2000 2 Oct 23 09:00 notes.txt -rw-r--r-- 1 1001 1001 2 Oct 23 09:00 old.txt $ ls -l old.txt notes.txt -rw-r--r-- 1 2000 2000 2 Oct 23 09:00 notes.txt -rw-r--r-- 1 alice devs 2 Oct 23 09:00 old.txt
Recursive changes
The -R option changes a directory and everything inside it.
sudo chown -R www-data:www-data www
The whole tree now belongs to www-data, the user under which
web servers run on Debian and Ubuntu. Double-check the path before running
a recursive chown; a mistake can break a system.
$ sudo chown -R www-data:www-data www $ ls -lR www www: total 4 drwxr-xr-x 3 www-data www-data 4096 Oct 23 09:00 html www/html: total 4 drwxr-xr-x 2 www-data www-data 4096 Oct 23 09:00 img -rw-r--r-- 1 www-data www-data 0 Oct 23 09:00 index.html www/html/img: total 0 -rw-r--r-- 1 www-data www-data 0 Oct 23 09:00 logo.png
Reporting changes
The -v option reports every file, while -c
reports only files whose ownership actually changed.
sudo chown -v jano:jano report.txt data.csv sudo chown -c jano:jano report.txt config.ini
In the second command, report.txt already belongs to
jano:jano, so only config.ini is reported.
$ sudo chown -v jano:jano report.txt data.csv changed ownership of 'report.txt' from alice:jano to jano:jano changed ownership of 'data.csv' from alice:devs to jano:jano $ sudo chown -c jano:jano report.txt config.ini changed ownership of 'config.ini' from alice:alice to jano:jano
Changing only specific owners
The --from option changes ownership only for files that
currently have the given owner, group, or both.
sudo chown -R -c --from=www-data jano www
Only files owned by www-data are changed. This is useful when
reassigning files of a removed or renamed account without touching other
files in the tree. The --from=user:group form matches both.
$ sudo chown -R -c --from=www-data jano www changed ownership of 'www/html/img/logo.png' from www-data to jano changed ownership of 'www/html/img' from www-data to jano changed ownership of 'www/html/index.html' from www-data to jano changed ownership of 'www/html' from www-data to jano changed ownership of 'www' from www-data to jano
Copying ownership
The --reference option copies the owner and group of another
file.
sudo chown --reference=old.txt config.ini
The file config.ini now has the same owner and group as
old.txt.
$ sudo chown --reference=old.txt config.ini $ ls -l old.txt config.ini -rw-r--r-- 1 alice devs 2 Oct 23 09:00 config.ini -rw-r--r-- 1 alice devs 2 Oct 23 09:00 old.txt
Symbolic links
By default, chown changes the target of a symbolic link. The
-h option changes the link itself.
sudo chown alice notes-link sudo chown -h root notes-link
The first command changed the owner of notes.txt, while the link
still belongs to jano. With -h, the link itself is
changed and the target is left alone. In recursive mode, links found
inside directories are not followed by default.
$ sudo chown alice notes-link $ ls -l notes-link notes.txt lrwxrwxrwx 1 jano jano 9 Oct 23 09:00 notes-link -> notes.txt -rw-r--r-- 1 alice 2000 2 Oct 23 09:00 notes.txt $ sudo chown -h root notes-link $ ls -l notes-link notes.txt lrwxrwxrwx 1 root jano 9 Oct 23 09:00 notes-link -> notes.txt -rw-r--r-- 1 alice 2000 2 Oct 23 09:00 notes.txt
Errors and safety
chown reports insufficient privileges and unknown names, and it
can refuse to operate on the root directory.
chown alice report.txt sudo chown nobody123 report.txt sudo chown -R --preserve-root alice /
A regular user cannot give a file away, even their own. A user name must
exist unless it is given as a number. The --preserve-root option
makes a recursive chown on / fail. Unlike
rm, chown does not enable this protection by
default, so it is worth using in scripts and aliases.
$ chown alice report.txt chown: changing ownership of 'report.txt': Operation not permitted $ sudo chown nobody123 report.txt chown: invalid user: ‘nobody123’ $ sudo chown -R --preserve-root alice / chown: it is dangerous to operate recursively on '/' chown: use --no-preserve-root to override this failsafe
Best practices for chown
- Check before -R: Verify the path of recursive changes.
- Use groups for sharing: Change the group instead of the owner when several users need access.
- Target precisely: Use
--fromto change only files of a specific owner. - Verify with -c: See which files were actually changed.
- Combine with chmod: Ownership and permissions together decide access.
Source
In this article, we have used the chown and chgrp
commands to change owners and groups, use numeric IDs, change directory trees,
select files by their current owner, and handle symbolic links.
Author
List all Linux tutorials.