Linux Commands to Add User to Group

We can use either usermod or gpasswd command to add user to group in Linux operating system. And both commands are very easy to use.

usermod command to add user to a group in Linux

usermod -a -G groupname username

gpasswd command

gpasswd is a Linux command dedicated for group administration. Command option -a use to add user to group in Linux.

gpasswd -a username groupname

Both usermod and gpasswd command works on every linux distributions including redhat, CentOS, Debian and Ubuntu Linux.

Now lets see an Example how to add a user to a group in linux

Let's assume we have a user on our Linux server called bob and we also have an administrative group called wheel. What we want is to add user bob to the wheel administrative group.

usermod -a -G wheel bob

linux add user to group using usermod command

And we can also use gpasswd command

gpasswd -a bob wheel

add user to group linux using gpasswd command

As you can see both commands are very easy to use, even though you will see the usermod command is most commonly used by administrators to add user to group in Linux.