-1

I accidentally added my user myuser to the group root using the command sudo usermod -a -G root myuser. Now I want to remove myuser from roots, but I am unable to do so. I tried the following:

deluser myuser root
sudo gpasswd -d myuser root

but I get the message

`Removing user myuser from group root
gpasswd: user 'myuser' is not a member of 'root'

I also tried sudo vipw, which supposedly allows me to edit the /etc/group file, which has the following:

root:x:0:0:root:/root:/bin/bash

and sudo vipw -g and sudo vigr have the following:

root:x:0:

which I think indicates that myuser is not in the root group. However, I know myuser is in the root group because when I su myuser and enter groups, I get the following groups:

root sudo

So, how can I remove myuser from the root group?

UPDATE

Note that the command groups output the following:

root sudo

whereas normally it should output

myuser root sudo

which means that something went awry when creating the myuser account, and that root is my primary group (first in the list). I believe this was the cause of my problem.

I believe this issue was resolved by my answer below where I think root was my primary group, blocking my ability to remove it as a group. I think this question might be helpful for others, but if I should delete it altogether, just let me know and provide an explanation.

modulitos
  • 335
  • 1
  • 3
  • 16
  • Any reason for the downvote? Sorry if I resolved this question too quickly, but it might be helpful for other users. Or, if anyone can offer some enlightenment on the solution, I'd be happy to accept a better answer. – modulitos Apr 22 '15 at 05:33
  • 1
    I downvoted the question because knowing how useradd interacts with /etc/passwd and /etc/group is a basic pre-requisite for managing information technology systems in a business environment. @peterh is correct that this question would do better at [unix.se], which is open to a broader range of questions about using unix systems, though his sneer at the other denizens of [sf] is both unnecessary and unpleasant. – Jenny D Apr 22 '15 at 13:34
  • @JennyD He knows the interaction of these tools and the passwd/group files, the question is about a mystical behavior of these tools. Closing and later deleting this question is destructive behavior, on my opinion. – peterh Apr 22 '15 at 15:38
  • 1
    @peterh The primary group lives in /etc/passwd, not in /etc/group, and since the OP only looked in /etc/group, obviously he was unaware of this fact - which, as I said, is something a unix sysadmin should know. This is why I consider the question off-topic for this site. It would be on-topic at [unix.se], but we don't migrate duplicates which is why it's closed instead of migrated. If you have anything further to add, you may post yet another rant to meta. – Jenny D Apr 22 '15 at 16:22

2 Answers2

1

It looks like root was the primary group of myuser (since it was the first group listed with the groups command).

So I changed the primary group using sudo usermod -g sudo myuser and then the root group was gone from myuser's groups.

modulitos
  • 335
  • 1
  • 3
  • 16
1

Try logging out and logging back in - gpasswd may not take effect until you do so.

g491
  • 973
  • 5
  • 7
  • Thanks for the input, but I tried a system reboot and it didn't affect the `root` group under `myuser`. I think my answer below fixed this problem, but I'm not sure why. I suppose it was an issue with `root` being my primary group? – modulitos Apr 22 '15 at 05:32