usermod
Change a user, for example add them to a group
What it does
usermod changes the settings of an existing user. Most often, their supplementary groups: -aG docker anna adds anna to the docker group so she can run containers without sudo.
New groups take effect from the next login: the user has to log in again or reconnect over SSH. groups <user> shows which groups a user is in.
Careful. Without -a, -G does not add but replaces the list of groups: the user drops out of all the others, sudo included. Always type -aG together.
Syntax
sudo usermod -aG <group> <user>
groups <user>Examples
Add the user anna to the docker group, keeping anna in the other groups
sudo usermod -aG docker annasame as:
sudo usermod -a -G docker anna,sudo usermod --append --groups docker annausermod— change a user-a— add to the groups instead of replacing them-G docker— a supplementary groupanna— who