How To Add A User To A Group?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-add-user-to-group/
PINTEREST
PINTEREST
INSTAGRAM

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 always we need root privileges to change user group.

List Users

Before starting to add user into a group we will list currently existing user accounts. There are a lot of different ways to list user accounts but I like to use following command.

List Users 
List Users 

List Groups

We will also list currently existing groups which is stored in a file /etc/group .

List Groups
List Groups

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 assign group to the files and directories user created.

In this example we will change user test primary group to the 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 . We will use -G option in order to specify other group.

LEARN MORE  Linux usermod Command Tutorial With Examples

  • 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

Some times we may need to add single user to the multiple groups in a single command. We can use -G options with multiple group names like below. the group names are delimited with command. In this example we will add usertestto the groups namedrootandmysql`

  • usermod is command
  • -G root,mysql will change test user group memberships

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-add-user-to-group/
PINTEREST
PINTEREST
INSTAGRAM