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 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
And we can also use gpasswd command
gpasswd -a bob wheel
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.