Change file ownership with chown

Assign a file or whole directory tree to a different user and group, common after root-created copies or when fixing web server permissions.

LinuxFilessecurityHigh risk
Run sudo chown www-data:www-data /var/www/html to give the web server user ownership of the document root.

01Command

Command
$ sudo chown user:group file-or-dir

02What it does

The syntax is chown owner[:group] target; chown alice file changes only the owner, while chown alice: file also sets the group to alice's login group. -R recurses through a directory tree (chown -R www-data:www-data /var/www/html). Verify with ls -l or stat -c '%U:%G %n'. For group-only changes, chgrp or chown :group file avoids touching the owner. Reference a group by ID with a leading colon-plus-number (:1000), and note ownership changes are recorded by auditd/SELinux contexts may need relabeling on SELinux systems.

03Risk

RiskHigh risk
RequirementsMust run as root or with sudo; usernames and groups must already exist
!Warning: Wrong recursive chown on system directories (/, /usr, /etc) can break the OS and sudo itself — always confirm the exact path before pressing Enter.

04Undo

Undo
$ sudo chown previous-owner:previous-group file-or-dir

05Sources

  • chown(1) — change file owner and group
    man7.org · technical · 2026-09-17
    Evidence: The chown man page documents setting owner and group via 'owner[:group]' syntax and the -R option to operate recursively.

Last verified: 2026-09-17 · Category: Files & Folders

06Related solutions