Summary
Here is the short answer: When a user is deleted its primary group is also delete, unless that group also contains other users. In this latter case the user is deleted but the group is not.
We can easily verify this ourselves.
Case 1: No other users in primary group of deleted user
First we consider the case where the primary group contains no other users.
Create the paul
user:
root@host:~# useradd paul
Check for the paul
group using getent
:
root@host:~# getent group paul
paul:x:1001:
Delete the paul
user:
root@host:~# userdel paul
Check for the paul
group using getent
:
root@host:~# getent group paul
root@host:~#
Notice that there is no output from this command. We can also try to delete the paul
group ourselves:
root@host:~# groupdel paul
groupdel: group 'paul' does not exist
This confirms that the paul
group no longer exists.
Case 2: Additional users in primary group of deleted user
Now we will check to see what happens if we try to delete a user whose group contains other users:
root@host:~# useradd user1
root@host:~# useradd user2
root@host:~# usermod -a -G user1 user2
root@host:~# groups user2
user2 : user2 user1
root@host:~# userdel user1
userdel: group user1 not removed because it has other members.
root@host:~# groups user2
user2 : user2 user1
root@host:~# getent group user1
user1:x:1002:user2
root@host:~# getent passwd user1
root@host:~# deluser user1
/usr/sbin/deluser: The user `user1' does not exist.
In this case the user1
user is deleted but the user1
group remains.