I recently set up some groups and users on my machine, and now I want to remove all those users and all those groups. Somewhat stupidly, I read on an Ubuntu forum or something like that that it was possible to just edit the textfile that contains all the group info. But now, whenever I start a terminal, I get

groups: cannot find name for group ID 1002

which is obviously not The Right Thing.

So, how can I remove all the groups and users I created a few months ago?

3 Answers 3


You can edit /etc/passwd and friends (/etc/group, /etc/shadow, /etc/gshadow) manually, but there's more risk of making a mistake (such as deleting a line you didn't mean to) than when using higher-level tools.

Use vigr rather than calling your editor directly on /etc/group (vigr -s for /etc/gshadow, vipw (-s) for /etc/passwd (/etc/shadow)). This has two benefits. First, these utilities lock the files to make sure someone or some other tools doesn't edit them at the same time. Second, they create a backup (/etc/group-, …).

Check if you have /etc/group-, or perhaps a backup from another tool (e.g. /etc/group.bak). It might be a little out of date, but it'll still be better than starting from scratch.

If you haven't modified /etc/gshadow, you can find the names of the missing groups, but not the numbers. If you've erased entries below 100, their names and numbers identical across all installations of a given version of Ubuntu (you'll still have to add local users to system groups as desired). Entries between 101 and 999 are allocated when a package is installed, and I can't think of an easy way to reconstruct these. Entries above 1000 are whatever you created.

I recommend setting up version control for /etc. If you'd done this, you could just restore from a working version. See Is there a system journal that I can install?. In a nutshell:

apt-get install etckeeper
etckeeper init

Your changes will be saved (“committed”) once per day, before and after installing packages, or whenever you run bzr commit from /etc. To see what you've changed, run bzr diff. To restore the latest committed version, run bzr revert group from /etc.

  • Seconded on the version control. Everyone should use etckeeper. May 9, 2011 at 22:32

It's true that you can just edit the text file /etc/group. It sounds like you have either deleted too much, or else left the file in a broken state. It needs to be one entry per line, in this format:


for "empty" groups, or


for groups with one member, or


for groups with multiple members. I put "empty" in quotes because you can also be a member of a group if it's set as your primary group in /etc/passwd — it's the fourth field there.

(The "x" can actually be a password hash, but that's very rarely used these days. It's almost certainly going to be all "x"s on your system.)

If you have extraneous blank lines, or badly formatted ones, that could mess things up.

The file also needs to have world-readable permissions.

Ideally, you have a backup of the file from a few months ago. But, I understand the real world. :)

There is also a file /etc/gshadow. If you are using group passwords (and like I said, almost nobody does), their hash values should be kept here instead of /etc/group, because this file is supposed to be only readable by root. This file can also be used to designate group administrators, who have the ability to add members using certain command-line tools. (I don't know of anyone using this functionality either.)

This file should be kept in sync with /etc/group. Using command-line or GUI tools to manage groups will do that automatically, which is another reason to consider using those rather than just editing the file. However, in actual practice, this file can be quite out of sync and even all munged up and your system will generally work fine. It won't result in the error you're seeing.

Gilles adds in a comment below that you could look in the /etc/gshadow file for information about how things should be. This won't have all the important information (like group ID number), but will have the group names and probably group membership information.

There may also be an /etc/group- file (note the - at the end) — this is the standard backup file created by the some tools for manipulating /etc/group/. If you're lucky, that'll have everything you need. (Often it's not much help, though, because it's just one backup. And programs like gpasswd don't update it.)

  • Someone didn't like this answer. Care to comment why? I am on drugs right now after my wisdom tooth removal, so it's possible I'm way off base. :)
    – mattdm
    Mar 9, 2011 at 22:16
  • Probably for not taking into account /etc/gshadow
    – camh
    Mar 10, 2011 at 7:15
  • I'll add that. But you can actually do a whole lotta ignoring gshadow and still have things work.
    – mattdm
    Mar 10, 2011 at 11:23
  • Wasn't me (I upvoted), but actually upon rereading I realize there are a couple of things missing in this answer, such as looking for /etc/group- and getting existing entries from /etc/gshadow. Mar 10, 2011 at 20:43
  • @Gilles — oh, good call on those as potential back-up sources.
    – mattdm
    Mar 10, 2011 at 20:46

Is it as simple as the passwd file has your primary group as 1002, but you have removed this group from the group file. So there is no way to resolve the name. Also files will still have the user and group ids that they have before.

It is not a good idea to add users and groups, better to disable them. If there is a reference some where left on the system, then you add a new user/group that takes the old id then it can look like they created the file, give them access to personal information etc.

You must log in to answer this question.

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