5

I have looked at the questions and answer here at U&L but I still cannot get my default group to change from a user.

[red@ws-red-l ~]$ whoami
red
[red@ws-red-l ~]$ groups
yellow green
[red@ws-red-l ~]$ sudo usermod -g green red
usermod: no changes
[red@ws-red-l ~]$ sudo usermod -G green red
[red@ws-red-l ~]$ groups
yellow green
[red@ws-red-l ~]$ touch file
[red@ws-red-l ~]$ ls -l file
-rw-r--r-- 1 red yellow 0 Feb 18 13:51 file

I would prefer if red did not belong to group yellow so when I do a touch file the group of the file would be green. What am I doing wrong here?

Anthon
  • 79,293
Red Cricket
  • 2,203
  • 1
    There are some caveats to using usermod according to its manual: You must make certain that the named user is not executing any processes when this command is being executed if the user´s numerical user ID, the user´s name, or the user´s home directory is being changed. usermod checks this on Linux, but only check if the user is logged in according to utmp on other architectures. – Ketan Feb 18 '14 at 19:08
  • 3
    You have to log out and log in again. – Laurentiu Roescu Feb 18 '14 at 19:08
  • 1
    Or log in on another terminal to check if all still works before you log out in your old one. – Hennes Feb 18 '14 at 19:11

1 Answers1

5

It works just as you ran it:

sudo usermod -g green red

You just need to log in as red again for the new groups settings to be read. You can check with:

red@oregano ~ $ whoami
red
red@oregano ~ $ groups 
red
red@oregano ~ $ sudo usermod -g users red
red@oregano ~ $ groups 
red
red@oregano ~ $ su red
Password: 
red@oregano ~ $ groups 
users
terdon
  • 242,166