4

In my Ubuntu 16.04 terminal, logged in as "john" (a normal user), I enter:

john@ubuntu-server:~$ groups john

Then the output goes:

john: john adm ......

So I wonder how john can be a user and a group at the same time. I really don't get it and I cannot find a satisfactory explanation on the Internet. Please enlighten me, thanks.

Ravexina
  • 57,256

1 Answers1

8

When you create a user, a group will be created with the same name and will be set as newly created user's primary group.

You can find out what your primary group name is using:

id -gn

The file which defines which group is your primary group lives at: /etc/passwd, run bellow command to get corresponding line to your user:

getent passwd $USER

it should look like:

username:x:1000:1000:Your Name,,,:/home/username:/bin/bash

Pay attention to second (1000), it's your primary user's group id.

or find out what groups your user is a member of using:

id -Gn

The file contains details about groups lives at: /etc/group, this command should show you the details about your user's primary group:

grep "^$USER" /etc/group

Same as:

getent group $USER

The result looks like:

groupname:x:1000:

Remember the 1000 from before? this is the group id which has been set as your primary group in /etc/passwd.

Then when you create new files, they would be owned by your user, and your primary group (which is same as your username and only one user is a member of that group, which is your user).

Ravexina
  • 57,256