Ubuntu – chown – Difference between user and user:user

chownpermissions

What is the difference between:

sudo chown $USER:$USER

and

sudo chown $USER

Why is it 2 times? Is the one user wrong? When I look at permissions with namei -l, I often see things like root root or proxy proxy.

Why does the owner have to be defined and listed 2 times?

Best Answer

The chown command is used to change the owner and group owner of a file or directory. Superuser privileges are required to use this command. The syntax of chown looks like this:

chown [owner][:[group]] file...

chown can change the file owner and/or the file group owner depending on the first argument of the command. Here are some examples:

chown owner file example:

chown bob file --> Changes the ownership of the file from its current owner to user bob.

chown owner:group file example:

chown bob:users file --> Changes the ownership of the file from its current owner to user bob and changes the file group owner to group users.

chown :group file example:

 chown :admins file --> Changes the group owner to the group admins. The file owner is unchanged.

chown owner: file example:

chown bob: file --> Change the file owner from the current owner to user bob and changes the group owner to the login group of user bob.

Please read this nice tutorial https://www.linode.com/docs/tools-reference/linux-users-and-groups. This show some info about user, groups ,permissions ,...

Related Question