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
Post new comment