3

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.

6

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

| improve this answer | |
  • What's the motivation behind this? Why would I want my own group, with only me in it? – Alexander - Reinstate Monica Oct 26 '18 at 20:42
  • @Alexander: From what I've found, 'usergroups' used to be a workaround to lack of flexible ACLs (that is, inability to grant just a few users access to certain files without having root privileges). So instead of asking root to create a group for this or that, you could directly manage the members of your own group. The presence of a mostly-defunct groupmems tool among Linux's user management tools seems to confirm this. – user1686 Oct 26 '18 at 21:30
  • @Alexander: It could also be that some security checks in the past gave greater privileges to members of the same group. (Although if that's true, I at least assume it wasn't for regular files, because those could be simply chmod g-rwx). – user1686 Oct 26 '18 at 21:32
  • @Alexander First I guess you already know that you can change this group, add other people to this group or even set it as others primary group too. When you login to system your primary group will be inherited by shell and other process and when you interact with system your primary group would effect that action. An example is creating a file which I already have mentioned it in my answer. typically all your files are available for write to you and your primary group (which by default is only you) because of umask 0002, depend on situation you might want to add other members to your group. – Ravexina Oct 26 '18 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.