How to add user to a Group on Linux

Managing users is an important activity in Linux. For a Sysadmin, you want different access permissions for developers, maintainers and moderators. Groups are an easy way to categorize users. Rights/permissions given to a group will be applicable to all its members. In this howto, I will tell you how to add users to a group.

I would suggest you to read about the two types of groups - Primary and Secondary, before proceeding.

Add a new group

[root]# groupadd developers

Add a new user to a Secondary Group

[root]# useradd -G developers chia

Please note that the user "chia" didn't exist, we used useradd to first create it and then assign it the developers group.

Add a new user to a Primary group

Use the -g option to change the primary group of a user.

[root]# useradd -g developers chia

Add a new user to multiple Secondary groups

[root]# useradd -G developers,ftp,admin chia

Add an existing user to a Secondary group using usermod

[root]# usermod -a -G developers chia

Its important to use the -a option here, without it you will just overwrite the secondary group setttings leading to only 'developers' in the secondary group. '-a' option tells usermod to append the user to the supplementary/secondary groups, its always used with -G option.

Change the Primary group of a user using usermod

[root]# usermod -g ftp

1 Comment

Groupon Clone (not verified)
July 20th, 2010 12:16 pm
Thanks for the nice information..

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.