How to Add User to Group in Linux Ubuntu 20.04 Complete Tutorial


Do You have added a user in wrong group, and want to add in right group? or Add new user in group, or want to add a user in multiple group?

You will get reply of all questions from this article.

Only reading full article gives you the complete guide on how to Add User to Group in Linux, I am using Ubuntu 20.04 Operating system but this operation will be the same on other Linux. You can perform this task on CentOS, RHEL, etc.

Disclaimer: This article does not cover to create user in Linux, you can read “How to create user in Linux step by step Guide”

Article Content

Check Available Users and Groups in Linux

To Check current logged in user is the member of which groups, user following syntax:


For the Example, I logged in with ‘vijay’ user, And I want to know to which groups are belongs ot vijay.

I run command ‘groups and I got following result

[email protected]:~$groups 
vijay adm cdrom sudo dip plugdev lpadmin sambashare
[email protected]:~$

If you want to details of groups for current user then run following command $id

[email protected]:~$id
uid=1000(vijay) gid=1000(vijay) groups=1000(vijay),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),118(lpadmin),129(sambashare)
[email protected]:~$

All information is saved into /etc/group file. You can see all the group information from this file by using same command.

$cat /etc/group

[email protected]:~$sudo cat /etc/group | tail -10
[email protected]:~$

You can retrieve the user information from /etc/passwd file.

[email protected]:~$sudo cat /etc/passwd | tail -10
systemd-coredump:x:999:999:systemd Core Dumper:/:/sbin/nologin
amit:x:1203:1203:Amitabh Bachhan:/home/amit:/bin/sh
[email protected]:~$

To Check the information of the groups belong to particular username.

$sudo id username

[email protected]:~$sudo id hema
uid=1202(hema) gid=1202(hema) groups=1202(hema)
[email protected]:~$sudo id nonu
uid=1004(nonu) gid=1004(nonu) groups=1004(nonu)
[email protected]:~$

How to create a new group

Before start adding and removing users form the group, I am going to show you, how can you create a group

To create new group you can use addgroup command followed by groupname

$sudo addgroup groupname

In the Example, I am going to add three groups name hr,mgr, and admin.

[email protected]:~$sudo addgroup hr
Adding group `hr' (GID 1005) ...
[email protected]:~$sudo addgroup mgr
Adding group `mgr' (GID 1006) ...
[email protected]:~$sudo addgroup admin
Adding group `admin' (GID 1007) ...
[email protected]:~$

You can check the information of new added group: See commands below.

[email protected]:~$sudo cat /etc/group | tail -10
[email protected]:~$

How to add Existing user to existing Group

You can add an existing user to an existing secondary group, use the usermod command followed by -a and -G option and the groupname and username

$sudo usermod -a -G groupname username

[email protected]:~$sudo usermod -a -G hr hema
[email protected]:~$

Check the status of groups for hema user.

[email protected]:~$sudo id hema
uid=1202(hema) gid=1202(hema) groups=1202(hema),1005(hr)
[email protected]:~$

How to add a user to multiple groups

It is quite easy to add a user to multiple groups. You can use the same command to add a user to the group but a little bit change. See in the example.

$sudo usermod -a -G group1,group2,group3 username

I am adding user “nonu” to groups hr,mgr,admin

[email protected]:~$sudo usermod -a -G hr,mgr,admin nonu
[email protected]:~$

Result is here:

[email protected]:~$sudo id nonu
uid=1004(nonu) gid=1004(nonu) groups=1004(nonu),1005(hr),1006(mgr),1007(admin)
[email protected]:~$

How to remove a user from Group

If you want to remove user from the group user gpasswd command followed by -d and username and group name

$sudo gpasswd -d username group

[email protected]:~$sudo gpasswd -d nonu hr
Removing user nonu from group hr
[email protected]:~$

Check the result:

[email protected]:~$sudo id nonu
uid=1004(nonu) gid=1004(nonu) groups=1004(nonu),1006(mgr),1007(admin)
[email protected]:~$

How to create a new user and assign new group

When your boss asks to create a new user ‘nitin‘, and it should be the member of mgr and admin group.

You can use command useradd command followed by -g for primary group -G for secondary group

$sudo useradd -g primary_group_name -G group1,group2 username

You can read full article on Create user in linux

[email protected]:~$sudo useradd -g users -G mgr,admin nitin
[email protected]:~$

Check the status of user nitin

[email protected]:~$sudo id nitin
uid=1204(nitin) gid=100(users) groups=100(users),1006(mgr),1007(admin)
[email protected]:~$


By now you have learnt many tasks of Linux System Administrator, You move one more step to become expert in Linux.

Manage users and groups is important task forever for Admin.

If you have any question related this article comment below.

You can write/contact me directly by using email address [email protected]


If you like our content, please consider buying us a coffee.
Thank you for your support!

3 thoughts on “How to Add User to Group in Linux Ubuntu 20.04 Complete Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *