Our Knowledge Base provides step-by-step guides, troubleshooting tips, and expert insights to help you manage VPS, dedicated servers, domains, DDoS protection, and more — all designed to make your experience with us fast, secure, and stress-free.
In this tutorial, we will explain how to add a user to a group in Linux systems. We will also show you how to remove a user from a group and how to create, delete, and list groups.
To add an existing user to a secondary group, use the usermod -a -G command followed the name of the group and the user:
sudo usermod -a -G groupname username
For example, to add the user liviu to the sudo group, you would run the following command:
sudo usermod -a -G sudo liviu
Always use the -a (append) option when adding a user to a new group. If you omit the -a option, the user will be removed from any groups not listed after the -G option.
On success, the usermod command does not display any output. It warns you only if the user or group doesn’t exist.
If you want to add an existing user to multiple secondary groups in one command, use the usermod command followed by the -G option name of the group separated by , (commas):
sudo usermod -a -G group1,group2 username
To remove a user from a group, use the gpasswd command wit the -d option.
In the following example, we are removing the user username from the group groupname:
sudo gpasswd -d username groupname
To create a new group , use the groupadd command followed by the group name:
sudo groupadd groupname
To delete an existing group, use the groupdel command followed by the group name:
sudo groupdel groupname
To change a user primary group, use the usermod command followed by the -g option:
sudo usermod -g groupname username
In the following example, we are changing the primary group of the user liviu to developers:
sudo usermod -g developers liviu
The following useradd command creates a new user named nathan with primary group users and secondary groups wheel and developers.
sudo useradd -g users -G wheel,developers nathan
To display complete user information, including all the groups of which a user is a member of, use the id command followed by the username:
id username
If you omit the username, the command will print the information about the currently logged-in user. Let’s check the user liviu:
id liviu
uid=0(root) gid=0(root) groups=0(root)
From the output above, we see that the primary group of the user is users and it belongs to wheel, storage, libvirt, docker, and kvm supplementary groups.
Use the groups command to display the user’s supplementary groups:
groups liviu
wheel storage power users libvirt docker kvm
If no username is passed to the groups command, it will print the currently logged in user’s groups.
In this tutorial, we have shown you how to add a user to a group.
The same commands apply for any Linux distribution, including Ubuntu, CentOS, RHEL,