To add a user to a group, use the usermod
command:
usermod -aG <groupname> <username>
The -a
option adds the user to the listed groups without removing them from groups they are already a part of and the -G
option designates that the listed groups will be secondary groups, rather than primary.
See this Stack Overflow post and nixCraft.