Users and groups are used on GNU/Linux for access and control to the system’s files, directories, and peripherals. Every linux user must know that how to create users and groups as it is very important, without it you will be very limited in various situatation. Let say, you have a directory that needs to be accessed with read/write permissions by one group of users and only read permissions for another group. This is entirely possible in Linux.
In this article, you gonna learn that how to create users in Linux then how to set their password and lastly how to add users in groups.
- Create users
- Create Groups
- Add users to groups
You can use any of following command to create user.
In following image, I have created a user “zeeshan“
Set Password to User Account
Now type password
Setting password for user “zeeshan” in following image.
There are two types of groups:
Primary Group: This group is created when you create a user and it’s created with same name as your username. Primary group is used by default when create or modify files/folders. A user can be a part of only one primary group.
Secondary Group: It is the optional group for a user, a single user can be assigned to multiple secondary groups.
Following command is used to create group in linux
In following example , I have created two groups “support” and “sales“
Add users to Groups
Now in this step we will add users in groups.
Set User Primary group
If you want to set or change a user’s primary group then use the following command.
usermod -g group-name user-name
-g It means primary group
In following image I have changed user “zeeshan” from primary group to “support“
Set User’s secondary group
If you want to set or change user’s secondary group then use following command.
usermod -G group-name user-name
-G Capital G use to set secondary group
I have changed user “zeeshan” secondary group to “sales“
To check User ID and Assigned Groups
Finally, you can see in image that group “support” and “sales” are assigned to user “zeeshan“
Remove User From a Group
Following command is used to remove a user from a group.
gpasswd -d user-name group-name
In following image, I am removing user “zeeshan” from “sales” group
That’s about it, you have successfully learned that how to create/modify users and groups in Linux.