How can I add a user to the existing group ?
In linux users may have different groups registered. By default adding a user to the linux system will create new user. There are different commands to change user group one of them is useradd which actually create new user and sets given group to the newly created user. As allways we need root privileges to change user group.
Change Primary Group
Linux users may have more than one group. We call them primary and other groups. We will change user test primary group to mysql. Primary group is used to assigne group to the files and directories user created.
In this example we will change user test primary group to the test
$ usermod -g mysql test
- usermod command will mdify usergroup
- -g mysql provides group parameter named mysql
- test is the user the group will be changed.
Add Other Groups
We can add user to the other groups. In this example we will add user test to the group root. Group root is not primary group of the test
$ usermod -G root test
- usermod is command that will change other group memebership
- -G root provides change for test user other group
- test is username
Add To Multiple Groups
We can add to Multiple groups like below.
$usermod -G root,mysql test
- usermod is command
- -G root,mysql will change test user group memberships