User and Group Management - RHCSA

How to add users to a group?

We can do it in two different ways.
  1. While creating a user
  2. After creating a user
While Creating a user :We can add user to a group as a supplementary group or primary group. When we do not add a group to a user, group will be created using user name. For an example if we create a user named paul , his primary group will be paul.
  • Add to a supplementary group
First create a group.
 
<group name> should be replaced by using relevant group name.
Let assume group name is HR. After creating the group retrieve it using tail -n 5 /etc/group or   
cat /etc/group | grep HR

After that you have to create a user by using following command.

<group> should be replaced by relevant group name and <name> should be replaced by user name.
-G for add group as supplementary group
You can retrieve information by using id command.
Example:

  • Add to a primary group 
First create a group and check its group id. If you want to add user to a existing group, check its group id by using ,
                                      cat /etc/group | grep <group name>
Using that command you can get the gid. Remember that you have to replace <group name>.
After that use following command.
<gid> should be replaced by using relevant gid.
After that u need to verify it. Use id command.
                         id <user name>
 
After creating a user: After user was created we need to modify the user by using usermod command.
Add user to a supplementary group, use following command
 Verify using id command
Add user to a primary group , use following command

Verify using id command


Exercise: 
Create users called Andrew, Paul, Mark, Susan, Kent. User id should be started from 5000. Andrew and Paul are in Cooking group as their supplementary group. Susan and Kent are in Service group as their supplementary group. Mark is in both groups. But his primary group is Management.  

Comments

Popular posts from this blog

Basic Configurations in Windows Server 2016 (2)

Group Management - RHCSA