Add an existing user to an existing group in Linux

If you already have a user on your Linux system and want to add that to an already existing Group on your Linux machine, you can add that user via the usermod command.

If your user is named ‘jack’ and you want to give it a secondary group of ‘www-data’, you can use this command.

$ usermod -a -G www-data jack

Each user also has a primary group assigned to it, you can change that for the user ‘jack’ as such.

$ usermod -g www-data jack

To list all the users that belong to a group, you can use the lid command.

$ lid -g www-data
 jack(uid=1234)

If you want to list all the groups that this user belongs to, you can use the groups command.

$ groups jack
jack : jack www-data