Updated: 10 October 2026 · Applies to: chown and chgrp on Linux: uutils coreutils 0.10 (default on Ubuntu 26.04) and GNU coreutils 9.x (Debian, AlmaLinux, Rocky Linux, Ubuntu 24.04); tested on Ubuntu 26.04.1 and AlmaLinux 10

To change the owner of a file in Linux, run sudo chown USER FILE. To change the owner and the group in one go, use sudo chown USER:GROUP FILE, and to change a folder together with everything inside it, add -R: sudo chown -R USER:GROUP /path/to/folder. To change only the group, use sudo chgrp GROUP FILE. Changing the owner needs root, so run these commands with sudo (or as root).

Check the current owner and group

Every file and folder has an owner (a user) and a group. ls -l shows both, in that order; for a folder itself (not its contents) use ls -ld. Our test site in /var/www:

cd /var/www
ls -l app
total 12
drwxr-xr-x 2 root root 4096 Oct 10 04:34 cache
-rw-r--r-- 1 root root    3 Oct 10 04:34 index.php
lrwxrwxrwx 1 root root   13 Oct 10 04:34 link -> /etc/hostname
drwxr-xr-x 2 root root 4096 Oct 10 04:34 uploads

ls -ld app
drwxr-xr-x 4 root root 4096 Oct 10 04:34 app

stat -c '%U:%G %n' app/index.php
root:root app/index.php

Here both the owner and the group are root. How to read the rest of the ls -l line: reading ls -l output.

Change the owner of a file

  1. Check that the new owner exists: id web (here the user is called web).
  2. Change the owner:
    sudo chown web app/index.php
  3. Check the result. Only the owner changed; the group stayed root:
    ls -l app/index.php
    -rw-r--r-- 1 web root 3 Oct 10 04:34 app/index.php

Add -v to see what changed. In our test, chown -v web:web app/index.php printed changed ownership of 'app/index.php' from deploy:www-data to web:web. With -c instead, chown reports only real changes and stays quiet when the owner was already right.

Change the owner and group together

Every form below was run in our tests, with the result shown after #:

sudo chown web:www-data index.php     # owner web, group www-data
sudo chown :www-data index.php        # group only, owner unchanged
sudo chown web:web index.php          # owner web, group web (the user's own group)
sudo chown 2001:2001 index.php        # numeric user and group IDs
sudo chown --reference=uploads index.php   # copy owner and group from another file

Ubuntu 26.04 note: the short form chown web: FILE (user, colon, nothing after it) is meant to set the user’s login group as well. GNU chown on AlmaLinux 10 did that, but the chown in Ubuntu 26.04 (uutils 0.10.0) changed only the owner and kept the old group. Write the group out, as in web:web, so the command does the same everywhere.

Numeric IDs work even when no user has that ID: ls -l then shows the numbers (2001 2001) instead of names, which is common after copying files from another server. The old dot form chown web.web still works, but both chown versions warned '.' should be ':', so use the colon.

Change the owner of a folder and everything in it

chown without options changes only the folder itself. Add -R (recursive) to include all files and subfolders:

sudo chown -R web:web /var/www/app

With -Rv you see each item. Our test on an uploads folder:

sudo chown -Rv deploy:www-data app/uploads
changed ownership of 'app/uploads' from web:web to deploy:www-data
changed ownership of 'app/uploads/a.jpg' from web:web to deploy:www-data

To find what is not owned by the right user yet (before or after a change), use find:

find /var/www/app -not -user web
find /var/www/app -not -group www-data

To change only files that belong to one old owner, for example after renaming an account, use --from. In our test this changed the items owned by web and left the uploads folder (owned by deploy) alone:

sudo chown -R --from=web deploy /var/www/app

Change the group of a file or folder (chgrp)

chgrp changes only the group and accepts -R, -v and -c like chown:

sudo chgrp www-data /var/www/app/index.php
sudo chgrp -R www-data /var/www/app/uploads

chown :www-data does the same. Changing only the group does not need sudo when you own the file and belong to the new group: in our tests a normal user who belongs to the devs group could switch its own file to devs, but got Operation not permitted for root, a group it is not in. To add a user to a group, run sudo usermod -aG GROUP USER (the new group applies from the user’s next login; in our test a fresh su session already listed it).

Symbolic links

By default, chown on a symlink changes the file the link points to. In our test, chown web:web app/link changed the owner of /etc/hostname, the link target. Use -h to change the link itself; the target then stays as it was. With -R, links inside the folder are not followed (our chown -R changed the link and left /etc/hostname as root:root). The -L option makes -R follow every link to a directory, so use it only when you mean it.

Avoid recursive mistakes

A typo such as sudo chown -R web:web / var/www (note the space) changes the whole system, and chown does not protect / by default: the help text of both versions says --no-preserve-root is the default. Add --preserve-root to scripts and aliases. In our test it stopped the command:

sudo chown -R --preserve-root web /
chown: it is dangerous to operate recursively on '/'
chown: use --no-preserve-root to override this failsafe

Take a backup or a snapshot before large recursive changes on a live server. If you broke ownership on a VPS and can no longer log in over SSH, the console in the client area still works: access your VPS with VNC.

Error messages and what they mean

  • Operation not permitted: you ran chown without sudo. Normal users cannot give files to someone else. Ubuntu 26.04 adds (os error 1) to the message.
  • invalid user: 'nosuchuser' or invalid group: 'web:nosuchgroup': the user or group does not exist. Check with id USER and getent group GROUP.
  • cannot access '/var/www/nofile': No such file or directory (GNU) or cannot dereference ... (Ubuntu 26.04): the path is wrong.

Ubuntu 26.04 ships chown and chgrp from the Rust rewrite of coreutils (chown (uutils coreutils) 0.10.0); the GNU version is still installed as gnuchown. Apart from the USER: form above and the wording of some error messages, every command in this article gave the same result with GNU chown 9.5 on AlmaLinux 10.

Typical ownership on web servers

  • cPanel hosting: your files belong to your cPanel user. You have no root access there, so you cannot run chown; ask support if ownership looks wrong.
  • Ubuntu and Debian with Apache or Nginx: the web server runs as www-data. A common setup is your own user as owner and www-data as group, with only upload and cache folders writable by the group.
  • AlmaLinux and Rocky Linux: the web server user and group are apache (httpd) or nginx.

In PHP, fileowner() returns the numeric owner ID; posix_getpwuid(fileowner($file))['name'] turns it into a user name (PHP 8.5 in our test printed web). PHP’s own chown() follows the same rule as the command: as a normal user it failed with chown(): Operation not permitted.

Ownership decides who a file belongs to; permissions decide what the owner, the group and everyone else may do with it. For those, see Linux permission codes such as 755 and 775, copying files with their permissions and ownership and, for extra users per file, access control lists.

Official documentation: GNU coreutils: chown invocation.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)