How to Add Users and Groups in Linux

Windows Articles

Is ReactOS a real alternative to Windows?

Oh! The eternal struggle of computer operating systems. Windows vs. GNU/Linux and Mac as a distant spectator However, there are also interesting...

How to install Firebird on Ubuntu 20.04/ 18.04?

Database management systems are sufficient for many kinds of projects. Of course, they abound with MySQL / MariaDB or PostgreSQL popular but...

How to disable Firewall in Windows Server 2019/2016

Hello! The Firewall performs an essential security task on any version of Windows Server. In fact, it has the mission of preventing...

How to install ArangoDB on Ubuntu 20.04?

In this post, you will learn how to install ArangoDB on Ubuntu 20.04 So let's go for it What...

How to create GPO in Windows Server 2019.

Hi, in today's post we will be looking at GPOs in Windows Server 2019. The Group Police Object are a set of...
Muhammad Nabeel
Muhammad Nabeel
Network and System Administrator

Users and groups are used on GNU/Linux for access and control to the system’s files, directories, and peripherals. So, 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 situation.

In this article, you will learn that how to create Linux users, how to set their password and how to add users in groups.

  1. Create users
  2. Create Groups
  3. Add users to groups

Create users

You can use any of following command to create user.

adduser [user-name]

OR

useradd [user-name]

For example in following image, I have created a user “john”

Set Password to User Account

passwd [user-name]

Now type password

Setting password for user “john” in below image.

Create groups

There are two types of user’s groups:

Primary Group: This is the group created when you create a user and it is created with same name as your username. But we can also change a user’s primary group. The primary group is used by default when create or modify files/folders. A user can be a part of only one primary group.

Secondary Groups: It is the optional group for a user. A single user can be assigned to multiple secondary groups.

So, below command is used to create group in Linux

groupadd [group-name]

In below example image, I have created two groups “it” and “hr”

How to Add users to Groups?

Then, 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

So for now, In below image i have changed user “john” primary group to “it”

Set User Secondary group

But if you want to set or change a user’s secondary group then use the below command.

usermod -G group-name user-name

-G Capital G means secondary group

So, I have changed user “john” secondary group to “hr”

See a User ID and Assigned Groups

id user-name

Finally, you can see in image that group “it” and “hr” are assigned to user “john”

Remove User From a Group

Following command is used to remove a user from a group.

gpasswd -d user-name group-name

So, In example image; I am removing user “john” from “hr” group

That’s it, Now you learned that how to create/modify users and groups in Linux.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Is ReactOS a real alternative to Windows?

Oh! The eternal struggle of computer operating systems. Windows vs. GNU/Linux and Mac as a distant spectator However, there are also interesting...

How to install Firebird on Ubuntu 20.04/ 18.04?

Database management systems are sufficient for many kinds of projects. Of course, they abound with MySQL / MariaDB or PostgreSQL popular but...

How to disable Firewall in Windows Server 2019/2016

Hello! The Firewall performs an essential security task on any version of Windows Server. In fact, it has the mission of preventing...

How to install ArangoDB on Ubuntu 20.04?

In this post, you will learn how to install ArangoDB on Ubuntu 20.04 So let's go for it What...

How to create GPO in Windows Server 2019.

Hi, in today's post we will be looking at GPOs in Windows Server 2019. The Group Police Object are a set of...