Skip to content
BENIBIX Learn

chown

Infrastructure⌨️ Linux & the Command LineUsers and Permissions

Also known as chown Command, Change Owner, File Ownership

A command that changes which user and group own a file.

Think of it like

Think of it like writing a new name on a lunch box. Now it belongs to someone else.

Example

Jack copies a website into place with sudo, so root owns it. The web server cannot write to it until Jack runs chown.

Why it matters

A program can only use files that its user may touch. A wrong owner is a common cause of errors.

Definition

chown changes who owns a file or folder. You give it a user, and you can add a group after a colon. Only the root user can give a file away, so you usually run it with sudo. Add -R to change a folder and everything inside it. The owner is the person the first set of rights applies to.

Example code

console
$ sudo chown www-data:www-data index.html
$ ls -l index.html
-rw-r--r-- 1 www-data www-data 512 Nov 16 10:05 index.html
The page now belongs to www-data. On Ubuntu, that is the user the web server runs as.
The two names after the letters are the owner and the group. chown changes those two names.

Common mistake

Running chown -R on the wrong folder, like /. It can break the whole system.

Key takeaways

  1. 1
    User:group. Set both at once.
  2. 2
    Needs sudo. Only root gives files away.
  3. 3
    -R for folders. Changes everything inside.

Compare

Learn it properly