How do I correct ownership of a selected Linux file?
chown changes a file’s owner and optionally its group. Determine the correct service or user identity first: ownership should match the application’s deployment model, not simply whichever account can make an error disappear. A broad recursive ownership change can break package-managed files or isolate a running service from its data.
Before you start
- An authorised SSH session on the Linux server.
Instructions
1. Verify both the current object and the intended identity
The example concerns one user-owned note. Confirm that the named group actually exists; an account’s primary group is not always the same as its username.
stat -c "%a %U:%G %n" -- /home/adminuser/server-notes/notes.txt
id adminuser
getent group adminuserUse the existing account and group records to establish the intended ownership before changing anything.
2. Change only the approved file
Run this only when adminuser:adminuser is the verified owner/group pair. A different service file may require a completely different identity.
sudo chown adminuser:adminuser -- /home/adminuser/server-notes/notes.txt
stat -c "%a %U:%G %n" -- /home/adminuser/server-notes/notes.txtThe exact path is changed without -R. Reinspect its mode because ownership changes can interact with special permission bits.
Check the result
- The intended account can access the file and the application’s required access still works. No parent directory or neighbouring file was changed.
Troubleshooting
- The file is a symbolic link
- Check the link and its target explicitly; default dereferencing behaviour may change the target’s ownership.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
