How-to

The chown Command with Examples

chown sets which account owns a file and which group it belongs to. Owners decide modes, so getting ownership right comes before every chmod.

What does chown do?

It changes the user owner and, optionally, the group of files and folders. Every file on Linux has exactly one owner and one group, stored as numeric IDs. The mode bits from The chmod command then decide what the owner, the group and everyone else may do. So when a service cannot write a file, check who owns it before changing any mode.

What are the basic forms?

CommandResult
chown irena report.pdfOwner becomes irena, group unchanged
chown irena:finance report.pdfOwner irena, group finance
chown irena: report.pdfOwner irena, group set to irena's login group
chown :finance report.pdfGroup finance, owner unchanged
chown 1005:1005 report.pdfNumeric IDs, no name lookup

A dot separator, as in irena.finance, still works in many versions but is deprecated; use the colon.

Who is allowed to change ownership?

Only root can give a file to another user. Regular users cannot, even for their own files; otherwise they could dodge disk quotas or plant files that look like someone else's. A file's owner may change its group, but only to a group the owner belongs to. In practice, run ownership changes with sudo:

sudo chown irena:finance /srv/shared/q4-forecast.xlsx

Changing the owner of an executable also clears its setuid and setgid bits on Linux, a safety rule that stops privileged programs from being handed around.

When should I use numeric IDs?

When names are missing or misleading. Container volumes are the common case: a process inside a container may run as user 1000 that does not exist on the host, or exists under a different name. chown -R 1000:1000 /srv/volumes/gitea sets exactly the ID the container expects. Numeric IDs also matter after restoring files from another machine; see chown recursively for finding orphaned IDs.

Can I copy ownership from another file?

Yes, with --reference:

sudo chown --reference=/etc/nginx/nginx.conf /etc/nginx/conf.d/billing.conf

The new file gets the same owner and group as the reference, which keeps a folder consistent without reading the owner first.

Can chown report each file it touches?

sudo chown -c ella:ella /home/ella/*.csv
sudo chown -v ella:ella /home/ella/notes.md

-c prints a line only for files that actually changed, which suits logs. -v prints every file, changed or not.

How do I check who owns something?

ls -l /srv/shared
stat -c '%U(%u) %G(%g) %n' /srv/shared/*
id ella

stat shows names and numbers together, so mismatches between machines stand out. id lists a user's ID and every group they belong to, which answers most "why can't this user write here" questions in one line.

Which real-world examples come up most?

  • New site folder for a deploy user: sudo install -d -o deployer -g www-data -m 2750 /srv/blog creates it with owner, group, mode and setgid in one step.
  • Logs a service must write: sudo chown nginx:nginx /var/log/nginx/shop on Rocky Linux or AlmaLinux.
  • A PostgreSQL data folder on the second drive: sudo chown -R postgres:postgres /mnt/nvme1/pgdata before pointing the service at it.
  • Files root created in a user's home: sudo chown -R ella: /home/ella/import.
  • Keys and their folder: an authorized_keys file owned by root inside a user's .ssh makes key login fail, as explained in Fix "Permission denied (publickey)".

What about symlinks?

By default chown changes the target the link points to when you name the link directly. To change the link itself, which matters for some audits and for links in shared folders, use -h: sudo chown -h ella: /srv/shared/current. In recursive runs the default is to leave links' targets alone; the flags are listed in chown recursively.

Does chown work the same on FreeBSD?

The forms above all work on FreeBSD 14. GNU-only options such as --reference and --from are not available there; use stat to read the owner and a find filter such as -user instead.

Keep Reading

chown recursively

Change owners across a folder tree with chown -R, choose how symlinks are handled and limit changes to files owned by one account.

Open

The chmod command

Change file modes with numbers or letters, understand what each bit does and use special bits like setgid and sticky correctly.

Open

Linux file permissions

Read ls -l output, understand owner, group and other bits, umask defaults, ACLs and why root and SELinux sit on top of it all.

Open

Linux user management

The full life of an account on a server: create, group, change, expire, lock, audit and delete, with the files behind each step.

Open

FAQ

Quick Answers

Use chown user:group followed by the file, for example chown irena:finance report.pdf.

Not to give files away. Only root can change the owner; owners may change the group to one they belong to.

Use chown :group file or the chgrp command.

It sets the owner and changes the group to that user's login group.

Run chown --reference with the source file and the target, available in GNU coreutils.