Add an existing user to an existing group in Linux

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, June 29, 2011

Follow me on Twitter as @mattiasgeniar

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


Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.