Quick take: The chown command changes the ownership of files and directories in Linux — which user and group own them. Use chown user file to set the owner, chown user:group file to set both, and add -R to apply it recursively. Changing ownership usually needs sudo.

Introduction

Every file in Linux is owned by a user and a group. Ownership decides who the permission rules apply to, so getting it right is essential — especially for web servers, shared directories, and files you copy or move between accounts. The chown command (short for change owner) is the tool for the job.

This guide explains how Linux ownership works, the full chown syntax, how to change the user and group, how to apply changes recursively, and the safe habits that prevent broken services.

Understanding File Ownership in Linux

Run ls -l and the third and fourth columns show the owner and the group:

ls -l app.log
-rw-r----- 1 irfan devops 1048 Jun 13 09:14 app.log

Here the user owner is irfan and the group owner is devops. The permission bits (rw-r-----) then decide what the owner, the group, and others may do. Ownership and permissions always work as a pair: ownership sets who, permissions set what.

chown Syntax and Basic Usage

The basic form is chown [options] owner file:

# Change the owner to irfan
sudo chown irfan report.txt

# Change the owner of several files at once
sudo chown irfan file1.txt file2.txt file3.txt

Because giving a file to another user is a privileged action, you almost always need sudo. Without it you will see chown: changing ownership: Operation not permitted.

Changing User and Group Together

Use the user:group syntax to set both at once:

# Set owner to irfan and group to devops
sudo chown irfan:devops report.txt

If you write a user followed by a colon and no group (chown irfan: report.txt), chown sets the group to that user's default login group. A dot can be used instead of a colon on most Linux systems: chown irfan.devops report.txt.

Changing Only the Group

To change only the group, prefix the name with a colon:

# Change only the group
sudo chown :developers report.txt

# Or use the dedicated chgrp command
sudo chgrp developers report.txt

Recursive Ownership with -R

The -R flag applies ownership to a directory and all of its contents — indispensable when deploying web applications:

# Hand an entire site to the web server user
sudo chown -R www-data:www-data /var/www/mysite

Use it deliberately on system paths. Running chown -R on the wrong directory (for example /) can change ownership of critical files and stop the system from booting or logging in. Double-check the path before pressing Enter.

Common chown Examples

# Give a web app to the Nginx/Apache user
sudo chown -R www-data:www-data /var/www/html

# Restore ownership of a user's home directory
sudo chown -R irfan:irfan /home/irfan

# Take ownership of a file you copied as root
sudo chown $USER:$USER downloaded-file.tar.gz

# Change ownership but follow a symbolic link's target
sudo chown -h irfan link-name

Best Practices and Safety

  • Always confirm the path before a recursive chown -R, especially with a leading slash.
  • Match the service user. Web files should usually be owned by www-data (Debian/Ubuntu) or nginx/apache on other distributions.
  • Use $USER to reclaim files you created with sudo so your normal account can edit them.
  • Pair with chmod. After setting ownership, set permissions so the owner and group have exactly the access they need — no more.

Final Thoughts

The chown command is short to type but powerful: it decides who owns each file and, by extension, who the permission rules apply to. Remember the user:group syntax, reach for -R when deploying whole directories, and treat recursive changes on system paths with respect. Combined with chmod, it gives you full control over Linux file security.

FAQ: chown Command in Linux

What is the difference between chown and chmod?+

chown changes who owns a file — the user and group — while chmod changes what each class of user is allowed to do with it (read, write, execute). You often use them together: chown to assign ownership, chmod to set the permissions for that owner, group, and others.

How do I change both the owner and group with chown?+

Use the user:group syntax. For example, chown irfan:devops report.txt sets the owner to irfan and the group to devops in a single command. You can also use a dot instead of a colon on most systems.

How do I change ownership recursively?+

Add the -R flag: chown -R www-data:www-data /var/www/mysite changes ownership of the directory and everything inside it. Use it carefully on system paths, since wrong ownership can break services.

Why do I need sudo for chown?+

Only the root user can give a file away to another user, so changing ownership normally requires sudo. Without elevated privileges you will get an 'Operation not permitted' error.

How do I change only the group of a file?+

Prefix the name with a colon: chown :developers file.txt changes only the group. Alternatively, use the dedicated chgrp command, for example chgrp developers file.txt.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support