chown

Give a file or a whole folder to another user and group with chown, and why it needs sudo.

>_ Try it: a simulated Linux, right here
Loading the terminal…

Examples

  • sudo chown deploy /srv/site/index.html
  • sudo chown -R deploy:deploy /srv/site
  • ls -l /srv/site
  • touch /srv/site/about.html
  • sudo chown www-data:www-data /srv/site/about.html
  • ls -l /srv/site

How it works

Every file has an owner and a group: ls -l shows them in the third and fourth columns. The owner decides who may change it (with chmod).

chown USER FILE gives the file to USER; chown USER:GROUP sets both; -R does a folder and everything inside. Only root may give files away, so on a server it is sudo chown.

Syntax

sudo chown [-R] USER[:GROUP] FILE...

Options

OptionWhat it does
USERthe new owner
USER:GROUPthe new owner and group at once
-Rrecursive: the folder and everything inside it

Good to know

  • "Permission denied" in a folder usually means it belongs to someone else: check with ls -ld FOLDER before reaching for sudo every time.
  • Be careful with -R on system folders: sudo chown -R on the wrong path can break a server.