Linux: How to Add a User to a Group

There are a couple of options to add a user to group(s) in Linux. The commands are gpasswd, usermod and adduser.

I recommend to use gpasswd to add a user to group, which is no harm.

gpasswd -a <USERNAME> <GROUPNAME>

You must use usermod command as follows:

usermod -aG <GROUPNAME> <USERNAME>

If you forgoet '-a' option (only with '-G' option like usermod -G ...), note that surprisingly it overwrites the existing group information.

If you are on Ubuntu, you can use adduser

adduser <USERNAME> <GROUPNAME>