How to Create Users and Groups in Linux from the Command Line

How to Create Users and Groups in Linux from the Command Line

How to Create Users and Groups in Linux from the Command Line

Home » News » How to Create Users and Groups in Linux from the Command Line
Table of Contents

When you administer a Linux server, you possible must create customers and teams. You may be restricted in a number of essential methods with out understanding tips on how to create customers. First off, new customers can’t be added to a system. Second, you may need to create a person to put in a bit of software program. As for teams, past having to create teams for the profitable set up of sure software program, it is a nice strategy to management person permissions for directories.

Likelihood is additionally, you will have to do that from the command line. Due to the need of this process, I need to stroll you thru the method of:

  • Creating customers.
  • Creating teams.
  • Including customers to teams.

Let’s dive in so you’ll be able to improve your Linux admin recreation.

SEE: Prime Instructions Linux Admins Have to Know (roosho Premium)

Creating customers

For this, we will likely be utilizing the useradd command. This command is fairly versatile and means that you can create customers who can log in and even customers who can’t (when making a person for a software program set up).

The fundamental syntax of the command is:

useradd [options] username

Say, you need to create the person olivia such that she has a house listing and might log in. When you have been to difficulty the command:

sudo useradd olivia

The person could be added, and not using a residence listing and be locked out of logging in. As a substitute of issuing the command with out arguments, let’s go along with this:

sudo useradd -m olivia

The above command would create the person and in addition create the person’s residence listing to match the username. So, in the event you seemed within the /residence listing, you’d now see olivia.

However what about that lockout difficulty? There are two methods you are able to do this. When you’ve already created the person, you possibly can difficulty the command:

sudo passwd olivia

You may be prompted to enter and confirm the brand new password. At this level, the person account will likely be unlocked they usually can log in.

If you wish to do that all in a single step, that command would seem like this:

sudo useradd -m olivia -p PASSWORD

The place PASSWORD is the password you need to use for the person olivia.

As soon as the person logs in, they will change their password through the use of the passwd command, getting into their present password, after which getting into/verifying their new password.

If you have to create a person that has no residence listing and is locked out from logging in, you are able to do this with the next instructions:

sudo useradd -M USERNAME
sudo usermod -L USERNAME

The place USERNAME is the title of the person so as to add.

The primary command creates the person and not using a residence listing, and the second command locks the person from logging in.

SEE: The way to Hook up with Linux Samba Shares from Home windows (roosho)

Creating teams and including customers

Now it’s time to create a bunch. Let’s create the group editorial. To do that, you’d difficulty the command:

sudo groupadd editorial

Now, we need to add our new person, olivia, to the group editorial. For this, we are going to make the most of the usermod command. This command is kind of easy to make use of.

sudo usermod -a -G editorial olivia

The -a choice tells usermod we’re appending, and the -G choice tells usermod we’re appending to the group title that follows the choice.

How have you learnt which customers are already a member of a bunch? You are able to do this the old school manner:

grep editorial /and many others/group

The above command will listing pertinent details about the group.

This Shows the Members of the Editorial Group.
this reveals the members of the editorial group picture jack wallen

One other technique for locating out who’s in a bunch is with the command members. This command isn’t put in on most distributions, however could be put in from the usual repositories. When you’re utilizing an Ubuntu distribution, the command for set up could be:

sudo apt-get set up members

As soon as put in, the command for itemizing out who’s in our editorial group could be:

members editorial

That’s way more environment friendly than utilizing grep and can solely show the member names for the group.

Here’s Another Way of Showing the Members in the Editorial Group.
right heres one other manner of exhibiting the members within the editorial group picture jack wallen

SEE: The way to Add an SSH Fingerprint to Your known_hosts File in Linux (roosho)

Consumer administration made easy

When you have been involved that managing customers on Linux could be a problem, it’s best to now have the ability to set these considerations apart. Reality be instructed, person administration on Linux is kind of easy — you simply must know which instructions to work with. For extra details about these instruments, difficulty the instructions man useradd, man groupadd, man usermod, and man members.

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
share this article.

Enjoying my articles?

Sign up to get new content delivered straight to your inbox.

Please enable JavaScript in your browser to complete this form.
Name