3

How can I remove a group (which was previously deleted) from a user which still references it? If I run groups, I get an error about a non-existent group:

$ groups
myuser dialout cdrom sudo dip plugdev fuse lpadmin sambashare groups: cannot find name for group ID 1001
1001

The usual way of using deluser doesn't work because the group name no longer exists and there seems to be no flag for using IDs:

$ deluser myuser 1001
The group `1001' does not exist.

Is there a more straight forward way to remove a group (by ID) from a user other than by recreating the group, deleting the group from the user, and then redeleting the group?

2
  • There's still the easy fix: recreate the group (--uid=1001), remove it from the user's groups, and delete it again. Oct 17, 2014 at 17:18
  • @JohnWHSmith No, that wouldn't change anything. The group is deleted, so the user is no longer in the group. The user's running processes are in the group, that's different. Oct 17, 2014 at 23:35

2 Answers 2

4

groups show you the groups you are in. So the problem is that your process thinks you still are in the now deleted 1001 group, from the deluser myuser 1001 command.

You still would get that error message from groups as long as the process you started thinks you are in the group. When doing these kind of things in bash for my own account, I normally start a new shell to make sure that things are as I want them to be in that shell.

In your case starting a new shell should solve the issue, if not then the group would still exists in /etc/group and then deluser would not complain.

4
  • Any idea about how to handle it in CentoOS ? deluser doesn't seem to exist, and userdel doesn't work. Finally, gpasswd apparently doesn't handle group ids...
    – Anto
    Apr 17, 2018 at 11:12
  • @anto It is completely unclear what mean by 'it' in your comment? Do you mean you cannot handle restarting the shell? In the OP's question the group is already deleted, whether done deluser, gppasswd or userdel is completely irrelevant.
    – Anthon
    Apr 17, 2018 at 12:13
  • "It" = op's question = "remove a group (which was previously deleted) from a user which still references it". I had the exact same issue under Centos, but deluser doesn't exist there, so I couldn't follow your solution. But I've finally solved it by re-creating the group and then removing it.
    – Anto
    Apr 17, 2018 at 14:32
  • I have the same problem but even when opening a new shell the problem persists. Also, I can confirm that the group is not in/etc/group. Any idea?
    – papillon
    Jul 27, 2022 at 9:13
-2

you can remove the reference to the group manually i.e. modify /etc/group

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .