Linux Add User to Group
Adding a user to a group is a fairly simple task. It is not as difficult as coding an entire program in the terminal. But most beginners are unaware of the commands and steps to do so. So, in this article on “Linux Add User to Group,” we are going to list the complete step-by-step…

Adding a user to a group is a fairly simple task. It is not as difficult as coding an entire program in the terminal. But most beginners are unaware of the commands and steps to do so. So, in this article on “Linux Add User to Group,” we are going to list the complete step-by-step procedure. Have a look at the detailed guide below.
Why groups matter in Linux
Linux uses groups to decide who can read, change or run files, and who can use certain features. For example, members of the sudo group (on Ubuntu and Debian) or the wheel group (on Fedora, RHEL and similar systems) can run administrator commands. Instead of giving permissions to every user one by one, you give them to a group and then add users to it.
Every user has two kinds of groups:
- Primary group: The main group of the user. New files the user creates belong to this group. Each user has exactly one.
- Secondary (supplementary) groups: Extra groups that give the user additional permissions. A user can be in many of these.
Note: All the commands below change system settings, so you need to run them with sudo or as the root user.
Add a new group to Linux
Before starting, you need to create the group if you don’t already have one. You can do that by typing this command in the terminal:
sudo groupadd groupname
Replace groupname with the name you want. To see whether a group already exists, run:
getent group groupname
If the command prints a line, the group exists. If it prints nothing, it does not.
Linux add user to group
To add an existing user to an existing group, use the following command:
sudo usermod -aG groupname username
Replace groupname and username with the correct names of the group and user. This is the same as usermod -a -G; the options are simply combined.
Important: Always include the -a (append) option. If you run usermod -G without -a, the user is removed from every secondary group that is not in your list. This is a common mistake that can even remove a user’s sudo access.
You can also use gpasswd, which adds the user to one group at a time:
sudo gpasswd -a username groupname
On Ubuntu and Debian, there is also a friendly shortcut:
sudo adduser username groupname
Add a user to multiple groups at the same time
There are times when you want to add the same user to several groups. To do this, list the groups separated by commas, with no spaces:
sudo usermod -aG ftp,admins,secondgroup username
Replace the group names with the correct ones for your system.
Change a user’s primary group
If you want to change the user’s primary group, use the lowercase -g option:
sudo usermod -g groupname username
This only changes the primary group. The user stays a member of their secondary groups. Files the user already owns keep their old group, so you may need to update them with chgrp if required.
Create a new user and add them to groups
You can create a user and add them to groups in one step:
sudo useradd -m -G group1,group2 username
sudo passwd username
The -m option creates a home folder, and the second command sets the user’s password.
How to check which groups a user belongs to
Use either of these commands:
groups username
id username
The id command also shows the numeric user ID (UID) and group IDs (GID). To list every member of a particular group, run:
getent group groupname
How to remove a user from a group
sudo gpasswd -d username groupname
On Ubuntu and Debian, you can also use sudo deluser username groupname. This removes the user from that group only; it does not delete the user account.
Troubleshooting: group change not working?
- Log out and log back in. Group changes apply to new login sessions. A user who is already logged in will not see the new group until they sign in again. A full reboot also works.
- Use newgrp for a quick test. Running
newgrp groupnamestarts a new shell with that group active, so you can test it without logging out. - “usermod: group does not exist”. Create the group first with
groupadd, and check the spelling. - “Permission denied”. You forgot
sudo, or your own account is not allowed to use sudo.
Frequently asked questions
What is the difference between -g and -G?
Lowercase -g sets the user’s single primary group. Uppercase -G sets the secondary groups, and you should combine it with -a to add instead of replace.
How do I give a user sudo rights?
Add them to the admin group: sudo usermod -aG sudo username on Ubuntu and Debian, or sudo usermod -aG wheel username on Fedora and RHEL-based systems. Only do this for users you trust.
How do I list all groups on the system?
Run getent group. It prints every group, one per line.
That’s all you have to do to create and manage users and groups in Linux. If you faced any problems in the process or need help, feel free to ask through the comments.
We hope this guide helped you add users to groups in Linux. Please don’t forget to share it on your social media platforms, and let us know your views and feedback in the comment section below.
More in Linux

How to Check IP Address in Linux
The Linux OS is interesting to many people. I’d say it’s the android of the computer world. This is in the sense that it gives more customizability and options to the user. Linux gives you more power and you control what you want to do or not to do. There are some simple tasks that…

How To Install New Fonts In Ubuntu
Ubuntu is a most user-friendly version of Linux and comes with a great list of fonts when you install. If you are not satisfied with the available list of fonts in Ubuntu, you can install additionally from other sources. Installing a font file on Linux is a pretty simple process. The below procedure works for…

How to Install Spotify on Linux
Spotify doesn’t need any introduction and it is the finest music streaming service available online. The installation of Spotify is a pretty straightforward process for platforms like Windows, Mac, Android, and iOS. But when it comes to Linux, you have to depend on the commands to install Spotify. Spotify has been officially supporting the Linux…
The week in tech, minus the noise.
New reviews, fixes and the stories that matter — once a week, straight to your inbox.
We only use your email to send the newsletter. Unsubscribe any time. See our privacy policy.
Comments