Adding root to a group

4

I am not new to Linux, but there's this strange behaviour I'm seeing on my Fedora 15 box. I want to add the superuser to a group called, say, thisgroup.

# usermod -a -G thisgroup root
# groups
# root bin daemon sys adm disk wheel
#

^^ thisgroup is absent. Surprisingly, when I thought of editing /etc/group, root was present there!

Anyone on why groups didn't show my new addition?

yati sagade

Posted 2011-07-04T19:28:14.893

Reputation: 175

Answers

7

From the manpage of the groups command:

Print  group memberships for each USERNAME or, if no USERNAME is speci‐
fied, for the current process (which may differ if the groups  database
has changed)

This is exactly your case: the group database has changed, but the group membership for the current process hasn't been updated. If you instead queried the group memberships for the root user you would have got the correct result.

matteo@teomint:~$ sudo usermod -a -G test matteo
matteo@teomint:~$ groups
matteo adm dialout cdrom plugdev lpadmin admin sambashare
matteo@teomint:~$ groups matteo
matteo : matteo adm dialout cdrom plugdev lpadmin admin sambashare test

Long story short: for the current process, root isn't member of thisgroup yet; you have to login again.

Matteo Italia

Posted 2011-07-04T19:28:14.893

Reputation: 1 490

Thanks. It didn't work without logging out and logging in. – Maksim Dmitriev – 2014-01-15T12:37:27.840

1

You need to logout and in again - with no argument the groups command prints the groups that the current process has which doesn't change when when you change the group database.

If you do groups root then you should see it listed as that consults the /etc/group file.

TomH

Posted 2011-07-04T19:28:14.893

Reputation: 2 558