How to Add Users and Groups in Linux

Windows Articles

How to install Django on Ubuntu 20.04?

Developing web applications is usually related to PHP frameworks. However, Python, which is a very versatile programming language, also has a framework...

How to install the Development and build tools on Ubuntu 20.04?

In this very short post, you will learn how to install a series of development and build tools on Ubuntu 20.04. These...

How to set a drive as read-only in Windows 10

Hello! Hard drives are a fundamental element in any operating system. Of course, Windows 10 is no exception. In fact, this is...

How to create a new KVM virtual Machine on Debian 10?

In the previous post, we explained how to install KVM on Debian 10. Now it's time to create a KVM Virtual Machine.

How to repair a USB drive in Windows 10.

Hi! USB sticks are undoubtedly very functional elements for working in Windows 10. Indeed, their use ranges from file management to creating...
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

How to install Django on Ubuntu 20.04?

Developing web applications is usually related to PHP frameworks. However, Python, which is a very versatile programming language, also has a framework...

How to install the Development and build tools on Ubuntu 20.04?

In this very short post, you will learn how to install a series of development and build tools on Ubuntu 20.04. These...

How to set a drive as read-only in Windows 10

Hello! Hard drives are a fundamental element in any operating system. Of course, Windows 10 is no exception. In fact, this is...

How to create a new KVM virtual Machine on Debian 10?

In the previous post, we explained how to install KVM on Debian 10. Now it's time to create a KVM Virtual Machine.

How to repair a USB drive in Windows 10.

Hi! USB sticks are undoubtedly very functional elements for working in Windows 10. Indeed, their use ranges from file management to creating...