How to change File Ownership (chown)
Linux is a multi-user operating system, and sometimes we have files in common folders that all users can access. To maintain security, as well as to handle the data access, Linux uses ownership. In the same manner, an object owned by you can not be accessed by anyone else, unless someone higher up gives permission, Linux ensures your file is accessed only by the specified users, or groups, using the
chown (change owners) command. With some experience
chown can be used to set even the group of the file.
chown [OPTION]... [OWNER][:[GROUP]] FILE... chown [OPTION]... --reference=RFILE FILE...
Common Options used with
like a verbose but report only when a change is made
-f, --silent, --quiet
suppress most error messages
output a diagnostic for every file processed
Refers to RFILE ownerships, and applies them
Recursively apply the permissions to files and directories
To make any edits to our files and observe the changes, let's see the current owner of the file.
File owner details:
ls -l fileName
delta' is the owner, and group respectively to which '
.bashrc' file belongs to.
Changing ownership to another user
Make a new user, using the command
adduser userName, using sudo privileges either by prefixing the command with
sudo, or by starting an elevated shell, using the command
sudo -s, to log in, and start an interactive shell (an interactive shell has
#at the end of the prompt, instead of a
List the file information using the command
ls -l fileName.
To change file ownership, run
chown <userName|userID> fileName.
To see if the change has been made, we can again run
ls -l fileName, or we could use the
-vflag with our
chowncommand depending on the verbosity desired, and use case.
Changing Group ownership, and using
- We have seen how to edit the owner user of our file. A few special cases for group ownership, using the
chowncommand, are as follows
We can change our group using the command in the format as follows
chown [OPTION]... :[GROUP] FILE...
And this will change only the group of your specified file.
To change both User, and Group ownership simultaneously
chown [OPTION]... [USER]: FILE... # When Group is to be made login group of User chown [OPTION]... [USER]:[GROUP] FILE... # When User, and Group are to be explicitly changed
-cflag ( report any changes if made )
-vflag ( report all changes, and errors ), and
--referenceflag ( use referred file ownerships for all files passed as arguments )
We have seen how
chown can be used in the terminal, for manipulating ownerships and ensuring files' security, on *nix-based operating systems. We have also covered suitable daily need options, with examples aiding in the use of the command.
chown can also be used to manipulate the group ownerships, and as specified in the previous section in 1.1, when used like that,
chown behaves like