25

On a standard Linux distribution (e.g. Ubuntu) there is usually /etc/group and /etc/group-, where the second one is only readable by root.

man group only describes /etc/group.

Thus my question: What is the purpose of /etc/group-?

2 Answers 2

25

It is a backup of the previous copy of the file that is version of the file before the last change. It is kept because it is very important file. You can delete it, but backups are a "good thing".

You can easily verify it. Try

# groupadd test
# diff /etc/group /etc/group-

There are other files also that are backed up the same way viz. /etc/passwd- /etc/shadow-.

All the user and group management utilities like useradd, usermod, userdel, groupmod, groupdel etc. create/update these backup files after successful execution of the command.

2
  • 1
    Ok, I guess this would be another reason to modify /etc/group via group-commands and not directly editing it. Commented Nov 29, 2011 at 8:38
  • @maxschlepzig, smart. I have updated my answer to mention the user and group management utilities. Commented Nov 29, 2011 at 8:55
2

I agree with @Sachin Divekar's answer that this is a "backup file" but I needed more information as to how the file is created and how its permissions are set. On CentOS6, running usermod to change group membership was (re)creating /etc/group- with permissions of 0644 instead of "only readable as root" as described in the original question.

usermod (and all the other user/group management utilities mentioned by @Sachin Divekar) is part of the shadow-utils package (I found the sources for shadow-4.1.5.1) and after digging through the sources I found a #create_backup method in commonio.c (see it at github.com) that is used by all the user/group utilities. The backup file is named after the source file postfixed with a "-" (in this case, '/etc/group-'), and the permissions of the backup file are set to the permissions of the source file &'ed with 0664.

This explains why—when /etc/group is chmod 0644—after running gpasswd or usermod to modify local group membership, /etc/group- is created if it doesn't already exist and it is chmodded to 0644.

You must log in to answer this question.

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