Permissions, users and access

Command chown

Change file owner

Linux · Bash examples · commands run on the selected server

When to use chown

Use chown when file ownership is wrong after a deployment or privileged operation. Changing ownership can alter which service can write data, so target specific paths and verify the expected service account first.

Syntax

chown [OPTIONS] OWNER[:GROUP] FILE…

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

NAME:GROUP
Set the owner and group at the same time.
-R
Recursively process the tree.
--reference=FILE
Take the owner and group from the sample in GNU chown.

Usage examples

Change owner of one file

sudo chown deploy ./report.txt

The report's owner changes while its group is left unchanged.

Assign owner and group

sudo chown deploy:developers ./project

Both owner and group change on the named directory, not automatically on its contents.

Copy owner and group

sudo chown --reference=./reference.txt ./report.txt

Owner and group are copied from a reference file to the target.

Notes and limitations

  • Changing ownership usually requires administrator permissions.
  • Recursive ownership changes may disrupt services; limit it to the desired directory and check the links.

Common questions and troubleshooting

Why does chown require elevated privileges?

Transferring ownership is restricted on typical Linux systems. Use authorised administrative access only for the specific intended paths.

Should I recursively chown the whole application?

Only after understanding which files belong to which services. Recursive changes can break private keys, package-managed files and shared data.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man chown.