← Users & Permissions
Linux · Users & Permissions
How to manage groups and group membership in Linux
Create groups and add or remove users from them with groupadd, usermod -aG, and gpasswd.
Create groups and manage who belongs to them. The -a flag on usermod is what keeps you from wiping a user's other groups. Run as root.
When adding a user to groups with usermod, always include -a (append). usermod -G without -a replaces all their supplementary groups, which can remove needed access.
# Create a group
sudo groupadd <group>
# Add a user to a group (append, keeps existing groups)
sudo usermod -aG <group> <user>
# Remove a user from a group
sudo gpasswd -d <user> <group>
# Verify membership
id <user>
getent group <group>Linuxgroupsusermod