Every Linux user must know how to manage your user and groups. You can assign user to the group. create a new group.
user and group management in linux terminal | flags and examples
![]() |
user and group management in linux |
Hello, guys welcome to the next session on Linux command line tutorial. Today You will learn about the "basics of group management" using Linux terminal.
I'm going to show you a bunch of commands,
Display groups, you are currently connected
![]() |
show your connected groups |
$groups
First I'm going to show you a command called "groups".
This command allows you to see which are the groups your current "user" is connected to.
List all groups in your Linux system
![]() |
List all groups |
$cat /etc/group
The next command I'm going to show you is to list all the groups which are available on your "operating system".
- There is a directory called "etc" and in this etc directory there is a file called "group" and all the groups are listed there.
So I'm going to write "cat /etc/group" and then press ENTER
And it's going to show you all the "groups" which are there on your system.
Create a new group
![]() |
Create a new group |
$sudo groupadd groupName
The next command is to add the "new group" to this list of groups.
So these groups are added to this file in date wise order.
Whatever groups you will add. It will be added to the bottom of this file.
Let's add a group. I'm going to write "sudo groupadd group_1" and press ENTER
And I am going to give my password. So this "group_1" will be added to the file in the "etc/group"
So just "cat" this once again and you can see this group is added to your group list.
Delete a group
![]() |
Delete a group in linux |
$sudo groupdel groupName
Next command is to "delete the groups".
For example, I want to delete the group called "group_1" then I can just write "sudo groupdel group_1" press ENTER
Add a user to the group
![]() |
Assign a user to the group |
$sudo gpasswd -a [userName] [groupName]
The next command I'm going to show you. How you can assign a user to a particular group?
For example, I want to assign the user (ansal) to the group (group_1)
So for this, you will write "sudo gpasswd -a ansal group_1". and press ENTER
- "-a" flag for adding the user to the group.
And then you can see this message "Adding user ansal to group group_1".
Remove a user from the group
![]() |
Delete a user from the group |
$sudo gpasswd -d [userName] [groupName]
If you want to "remove a user" you can just write "sudo gpasswd -d ansal group_1" and press ENTER
- Instead of "-a" flag you can use the flag "-d" for removing the user from the "group".
And you can see this message "Removing user ansal from group group_1".
Conclusion
So in this way, you can use "group management".
And these are some of the commands which you can use for group management in your Linux operating system using the terminal.
I hope you enjoyed this tutorial please rate comment and bye for now.
HAVE A NICE DAY💞