What is the command to add a user to a group?
sudo usermod -aG docker tariq
-G names the supplementary groups and -a appends instead of replacing. Leave out -a and the account loses every other supplementary group, including sudo or wheel. That mistake has locked many admins out of sudo on their own machines, so the two letters always travel together. An equivalent that cannot make this mistake is sudo gpasswd -a tariq docker, which adds exactly one membership.
Several groups at once are comma-separated with no spaces: sudo usermod -aG adm,systemd-journal tariq gives read access to most logs.
Why does the user not see the new group yet?
Group lists are read at login. Existing sessions keep the groups they started with, so id in an old terminal shows nothing new. Options:
- Log out and back in, including closing SSH multiplexed connections that reuse an old session.
- Run
newgrp dockerto start a subshell with the new group as the active one. - Run
sg docker -c 'docker ps'to use the group for one command.
For service accounts, restart the service: a running PHP-FPM pool or web server started before the change will not pick it up on its own.
What is the difference between primary and supplementary groups?
Each account has one primary group, stored in /etc/passwd, and any number of supplementary groups, listed in /etc/group. New files a user creates belong to their primary group, unless the folder has the setgid bit. Supplementary groups add access without changing file ownership.
| Task | Command |
|---|---|
| Add a supplementary group | usermod -aG web tariq |
| Change the primary group | usermod -g web tariq |
| Set the exact supplementary list | usermod -G web,adm tariq |
| Remove one membership | gpasswd -d tariq web |
| Create a group | groupadd -g 3100 web |
Changing a primary group does not change files the user already owns; run find / -xdev -user tariq -group oldgroup to see what keeps the old group.
How do I list group members?
getent group web id tariq groups tariq
getent group shows supplementary members only. Users whose primary group is web do not appear there; find them with getent passwd | awk -F: -v g="$(getent group web | cut -d: -f3)" '$4==g {print $1}'.
Which groups matter on a server?
| Group | Grants | Systems |
|---|---|---|
sudo | Full sudo rights | Ubuntu, Debian |
wheel | Full sudo rights; su on FreeBSD | Enterprise Linux, FreeBSD |
adm | Read most files in /var/log | Ubuntu, Debian |
systemd-journal | Read the full journal | All systemd images |
docker | Control the Docker daemon, equal to root | Where Docker is installed |
www-data, nginx | Web server file access | Debian family, Enterprise Linux |
Treat docker membership as root access: anyone in that group can start a container that mounts the host's root file system. Give it only to people who already have sudo, or use rootless Docker or Podman instead.
How do groups help with shared folders?
Create a team group, give the folder to it with the setgid bit, and every new file inherits the group:
sudo groupadd design sudo usermod -aG design ola; sudo usermod -aG design jun sudo install -d -g design -m 2775 /srv/design
Mode and ownership details are in The chmod command and Linux file permissions. For broader account tasks, see Linux user management.
Does this differ on FreeBSD?
Slightly. FreeBSD 14 uses pw groupmod web -m tariq to add a member and pw groupmod web -d tariq to remove one. The idea of primary and supplementary groups is the same.
Keep Reading
Linux user management
The full life of an account on a server: create, group, change, expire, lock, audit and delete, with the files behind each step.
OpenLinux file permissions
Read ls -l output, understand owner, group and other bits, umask defaults, ACLs and why root and SELinux sit on top of it all.
OpenThe sudo command
How sudo decides who may run what, the flags you use daily, safe sudoers rules, logging and the habits that keep root powers contained.
OpenDocker hosts
One box, many Compose stacks: a reverse proxy on ports 80 and 443 routes every container by hostname.
OpenFAQ
Quick Answers
Use usermod -aG with the group name. The -a flag appends; without it, other supplementary groups are removed.
Membership is read at login. Log out and in again, or use newgrp for the current shell.
Run gpasswd -d followed by the user and the group.
It is equivalent to root access, so give it only to people who already have sudo.
Use usermod -g with the new group. Existing files keep their old group until changed.