Linux Groups

Linux Logo

Linux Groups

Primary Groups

Each user is a member of exactly 1 primary group. This can be found by using

cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
systemd-network:x:101:103:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
_apt:x:103:65534::/nonexistent:/usr/sbin/nologin
pi:x:1000:1000:,,,:/home/pi:/bin/bash
messagebus:x:104:110::/nonexistent:/usr/sbin/nologin
_rpc:x:105:65534::/run/rpcbind:/usr/sbin/nologin
statd:x:106:65534::/var/lib/nfs:/usr/sbin/nologin
sshd:x:107:65534::/run/sshd:/usr/sbin/nologin
avahi:x:108:113:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/usr/sbin/nologin
lightdm:x:109:114:Light Display Manager:/var/lib/lightdm:/bin/false
systemd-coredump:x:996:996:systemd Core Dumper:/:/usr/sbin/nologin
pihole:x:999:995::/home/pihole:/usr/sbin/nologin
rtkit:x:111:117:RealtimeKit,,,:/proc:/usr/sbin/nologin
pulse:x:112:121:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
saned:x:113:123::/var/lib/saned:/usr/sbin/nologin
colord:x:114:124:colord colour management daemon,,,:/var/lib/colord:/usr/sbin/nologin
hplip:x:115:7:HPLIP system user,,,:/var/run/hplip:/bin/false

and inspecting the 4th column. It will contain the GID.
You can then take the GID and

To resolve the GID to a Group Name

cat /etc/group | grep 995
pihole:x:995:www-data

Secondary Groups

Users can be a member of many secondary groups.

groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev lpadmin gpio i2c spi

The first group listed is the primary. All the other groups are secondary.

New Group

sudo groupadd groupx

Delete Group

sudo groupdel groupx

What Groups is User Member of

Current User

groups

Specific User

groups root

Check Groups

cat /etc/group

Add User to Group

sudo usermod -aG groupx userx

-a = Append
-G = Group

OR

sudo gpasswd -a userx groupx

-a = Append

User needs to re login to take effect

Change Users Primary Group

sudo usermod -g groupx userx

-g = Primary Group

User needs to re login to take effect

Remove User from Group

sudo gpassd -d userx groupx

/etc/group File

Lists all the groups on the system

  1. Column: Group Name
  2. Column: Password ( Rarely Used )
  3. Column: Group ID | GID
  4. Column: Which Users are a member of this group