chown - Difference between user and user:user

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 ,...


It is not user:user, but user:group.

This is command format

chown [OPTION]... [OWNER][:[GROUP]] FILE...

Group of users may include many users. Here is some information regarding groups:

Linux uses groups as a way to organize users. Groups organize collections of accounts, primarily as a security measure. Control of group membership is administered through the /etc/group file, which shows a list of groups and its members. Every user has a default or primary group. When a user logs in, the group membership is set for their primary group. This means that when a user launches a program or creates a file, both the file and the running program will be associated with the user’s current group membership. A user may access other files in other groups, as long as they are also a member of that group and the access permissions are set. To run programs or create a file in a different group, the user must run the newgrp command to switch their current group.

A file is owned by a user and a group. By default it is owned by the user who created the file and his default group, unless it is changed.

In your case user root is a member of group root.


man chown gives description and usage and other useful info on chown command.

NAME
       chown - change file owner and group

SYNOPSIS
       chown [OPTION]... [OWNER][:[GROUP]] FILE...
       chown [OPTION]... --reference=RFILE FILE...

Form the info given by man page, we may know that chown $USER:$USER changes owner and group of target file to $USER, while chown $USER only changes owner of target file to $USER, leaving group of the target file unchanged.

Details (from man page) follow:

Owner  is  unchanged  if  missing.   Group is unchanged if missing, but changed to
login group if implied by a ':' following a symbolic OWNER.  OWNER and  GROUP  may
be numeric as well as symbolic.

So chown $USER:$USER can be shortened as chown $USER:.

Outputs like root root from namei -l command mean that the owner and group of that file are both set to root. That's not owner defined or listed twice. Owner and group are two related but different concepts. And a file always has a owner and a group.


As to use chown command, great chances are superuser privilege is required, since one is likely to transfer the ownship of a file when using chown command. However, that is not always the truth.

Say, we have a user named 'test', who belongs to several groups. id command gives following output:

uid=1000(test) gid=1000(test) groups=1000(test),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),110(sambashare)

And user 'test' owns the following file:

-rw-r--r-- 1 test test 0 May 27 23:34 test_file

Then we can change the group of test_file to sambashare without superuser privilege, as user 'test' belongs to 'test' group and 'sambashare' group at the same time, user 'test' already owns enough permission to change the group of the file.