Change the owner of a file or directory
Medium risk
What do risk levels mean?
- Read-only
- Inspects state without changing anything.
- Low risk
- Reversible with a routine follow-up command.
- Medium risk
- Changes state; undo path documented.
- Destructive
- Deletes or overwrites; confirmation required.
Transfers ownership of a path to another user — typically after copying files as root or fixing a web server's document root.
filespermissionschownownership
Parameters
File or directory whose owner to change.
New owner, as "user" or "user:group".
The owner the path had before the change (recorded in the inspect step); used only by undo.
Commands
Record the current owner and group so you can restore them
ls -ld "<path>"Change the owner (append -R yourself for a whole tree, after checking it)
sudo chown "<owner>" "<path>"Verification
ls -ld "<path>"The listing shows the new owner (and group, if given).
Undo
Restore the owner recorded by the inspect step before the change
sudo chown "root" "<path>"Pitfalls
- Changing ownership usually requires sudo; regular users cannot give files away.
- A recursive chown on the wrong path (e.g. / from a mistyped variable) is catastrophic — double-check the path before adding -R.
- System-managed paths (package installs, service homes) expect specific owners; changing them can break the service.