The Command
Read this before you run it: always write -aG, never -G alone. -G sets the complete list of supplementary groups, so usermod -G docker deploy removes deploy from every other group it was in, including sudo or wheel. On a server where deploy is your only admin account, that can cost you sudo access. The -a (append) flag adds the new group and keeps the existing ones.
sudo usermod -aG docker deployHere docker is the group and deploy is the user. Both must already exist. The command prints nothing when it succeeds. It works the same on Ubuntu, Debian, AlmaLinux, and Rocky Linux.
Check the Result
id deploy
groups deployid shows the user ID, the primary group, and all supplementary groups with their numbers. groups prints only the group names. To see every member of one group, ask the group database:
getent group dockerWhen the New Group Takes Effect
Group membership is read when a user logs in. A session that was already open keeps its old groups, so id without a user name, run in that session, may not show the new group yet, while id deploy already does. The user has to log out and log in again; for SSH that means closing the session and connecting again.
To use the new group in the current shell without logging out, start a subshell with it:
newgrp dockerThis only affects that one shell. Services that run as the user, such as a systemd unit, pick up the change when they are restarted.
Other Ways to Add a User to a Group
| Command | Where |
|---|---|
sudo gpasswd -a deploy docker | All distributions |
sudo adduser deploy docker | Debian and Ubuntu |
sudo usermod -aG docker deploy | All distributions |
gpasswd -a adds one user to one group and cannot remove other groups by mistake. On Debian and Ubuntu, adduser with two names does the same. On AlmaLinux and Rocky Linux, adduser is another name for useradd and does not accept this form; see useradd vs adduser.
Add a User to Several Groups
Separate the groups with commas and no spaces:
sudo usermod -aG docker,adm,www-data deployCreate the Group First
If usermod reports that the group does not exist, create it:
sudo groupadd developers
sudo usermod -aG developers deployRemove a User from a Group
sudo gpasswd -d deploy dockerOn Debian and Ubuntu, sudo deluser deploy docker does the same. Neither command deletes the user or the group. The user's primary group cannot be removed this way.
Groups You Will Meet on a Server
- sudo or wheel: members may run commands as root. The group is
sudoon Debian and Ubuntu andwheelon AlmaLinux and Rocky Linux. See how to create a sudo user. - docker: members can use Docker without sudo, which is close to root access. The setup is in how to install Docker on Ubuntu.
- www-data, nginx, or apache: the web server group, useful for shared write access to a site folder.
- adm and systemd-journal: members can read many system logs.
Troubleshooting
- The user still cannot use the group: the session is older than the change. Log out and in again, then check with
id. - The user lost sudo:
-Gwas used without-a. Log in as root or another admin and add the sudo group back withusermod -aG. - User does not exist: check the spelling with the list of users.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations