Create A New User

Today’s article is going to be quick and easy as we simply discuss how you create a new user. This is a fairly basic task and shouldn’t take too long to cover. If you want to create a new user, read on!

If it’s not obvious,  you have a user account. You use this information even if you don’t realize it. Indeed, you use this information when you log into your computer to begin with. When you log in, you’re logging into your user account.

There are other users. You may have a root account or an account for MySQL. If you want to know how many different users are on your system, you can follow along with the following article:

How To: List All Users In Linux

One of the things that helps keep Linux secure is that it’s a true multi-user environment. You can only perform operations on the files you have access to. This is why you use sudo or root.

Managing users is a fundamental task in Linux. This article is going to cover how to create a new user and we’ll be doing so in the terminal. This should be fairly universal and you won’t need to install anything as user management tools will be included by default.

We will use a couple of tools, however. The first among them is:

useradd:

The useradd command is basic and, as the name implies, is used to add new users. There’s nothing complicated about it in today’s article and you can be certain that this is already a tool available to you.

If you’re curious about the command, check the man page:

If you do so, you’ll see that it’s described as this:

useradd – create a new user or update default new user information

So, that’s the correct tool for this job.

passwd:

The other tool we’ll be using is the passwd command. You can again tell by the name what the tool is going to do. Simply, it’s used as a password management tool. This too isn’t all that complicated and you can check the man page with this command:

If you do so, you’ll see that I wasn’t kidding and that this tool does what you think it does. It’s described like so:

passwd – change user password

This is the correct tool for the job. After we create a new user, we’ll assign them a password. If the user wishes, they can change that password on their own.

Create A New User:

As mentioned above, we’ll create a new user with terminal-based tools. This is a nice and universal way to do things. Sure, there are GUI tools out there but this is going to work on any Linux system you’re likely to engage with. You can crack open your favorite terminal, often by just pressing CTRL + ALT + T on your keyboard.

First, we’ll create a new user with the useradd command. The syntax is very simple:

For example:

Now, we’ll add a password. This is also a simple command:

For example:

You’ll be asked to enter the password a couple of times. This is to help ensure that you’ve not made any typographical errors while entering the password. It’s all basic stuff.

Next, you can verify that the new user account has been created. For this next step, we’ll simply use cat and grep.

Again, here’s an example:

The output should look a little something like this:

If you find your user, you’ve done this properly and you’ve learned how to create a new user. I told you that it wouldn’t be too complicated!

Closure:

So… This is an article about how to create a new user. It’s a pretty basic task but one you might just want to know about. You never know when you’ll need to create a new user but now you know where to look if you do need to. User management can be a pretty important task, especially for a server admin.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Show User Information In The Linux Terminal

There comes a time in many Linux journeys when you want to know how to show user information in the Linux terminal. Well, if you’ve been waiting for such an article, this article is for you. After all, knowing about the various users might be important information for you.

You may not realize this, but your Linux system has all sorts of users. They belong to varied groups, sometimes more than one group at a time. Unless you’re already familiar with this subject, you probably have more users than you realize. 

That’s perfectly okay. It’s entirely normal to have different users. Linux is a user-oriented operating system. Users have varied permissions and can perform different tasks based on those permissions. 

This actually shouldn’t be a complicated article. It’s just a couple of commands, though the command may not be well-known among the newer Linux users. New users should familiarize themselves with the concepts of a multi-user system and with groups.

Anyhow, you shouldn’t need to install anything. The tools we’ll be using should be installed by default. You will need an open terminal. So, you have been warned. After all, it was right there in the title!

lslogins:

The tool we’ll expose you to today is ‘lslogins‘, which should be installed by default. You can verify that lslogins is installed with this command:

And, if you check the man page (with man lslogins) you’ll see this:

lslogins – display information about known users in the system

So, sure enough, that looks like it’s the correct tool for the job. Our goal is to show user information in the Linux terminal. This looks like a good way to go about it.

Show User Information In The Linux Terminal:

Yes, we’re doing this in the terminal. You can frequently open your terminal by pressing CTRL + ALT + T. Otherwise, you’ll find a terminal emulator somewhere within your application menu. It’s likely to be in the admin section of said menu.

With your terminal open, you can start with the basics. That is, we’re going to show all the known users with the lslogins command. That syntax is so simple.

You’ve got a lot of users. You may not know it yet, but you do. Here’s an example output from my system:

Now, that’s all well and good.

But…

Let’s say you only want to show user information about one single user. That’s fine and you can do that in a variety of ways. You can also do it just as easily with the lslogins command, simply by using the -u flag. 

The syntax is as follows:

An example output might look like this:

And there’s the information about the root user. You can try with your username and get information about things like the groups you belong to and more. Go ahead and give it a shot, you won’t break anything. I promise you won’t break anything with this command!

Closure:

You never know when you’re going to want to show user information in the terminal. It is useful information, especially when debugging things like permission errors. You may find you need to add yourself to a group or things like that. So, store this command away in your mental bank and save it for when you need this information.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: List All Users In Linux

If you want to list all users in Linux, this is the article for you. It should be a fairly short article, but it should tell you how to list all users. So, there’s that. By that, I mean it’ll probably do what it says on the tin, namely telling you how to list all your users.

You may want to check the list of users from time to time. Applications may add users, you may have added users, malicious software or people may have added users, etc… There are other reasons to list all users, but you get the idea.

This is a beginner-level exercise, so you shouldn’t have any difficulty with it. It should also be reasonably short, which is nice! If you find any mistakes or have any questions, scroll down and leave a comment. You can also ask on the lovely Linux.org forums.

Without further ado…

List All Users:

Once again, we start with opening the terminal. To do this, you just press CTRL + ALT + T and the terminal should open. That’s true on most distros that I’ve encountered. If not, you will still need an open terminal.

Got it open? Good, ’cause it’s a pretty easy operation. The file you’re looking for is ‘/etc/passwd’, which is a plain text file that’s in conjunction with the /etc/shadow file. Like most text files, it’s easy enough to work with them in the terminal.

You probably shouldn’t edit /etc/passwd by hand, but we’re just going to be viewing it.

So, to show the content of the file (and see the list of users):

If you want to show fewer results at a time, you can just use:

If you want, you can ‘grep’ a specific user. Just pipe the output to grep and you’re good to go. It looks like this:

If you want to use that format AND have numbered lines, one way of finding out how many users there are, then just use:

Though you could just as easily have used this to get the number:

If you want to list just the users, you can use ‘awk’ and pick the first column like this:

And that’s about it, really. You’ve now listed all the users – and counted ’em!

Closure:

That’s it! That’s all there is to it, and you’ve learned a little bit more – this time how to list users in Linux. I told you that it’d be pretty painless and easy. Plus, this is another article for the books – and this one authored early enough to give me some time to keep scheduling them ahead of time.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Properly Delete a User’s Account

Today’s article will show you how to properly delete a user’s account. It’s a pretty basic task and an astute observer would note that I’ve not yet written an article about creating user accounts. I may have to write said article at some point, because why not? This promises to be a pretty easy and brief article!

When you install some software, it may add a user. When you remove that software, it may just leave that user behind. You may have multiple people using your devices, or you may be working in a corporate environment. Either way, there comes a time when you may want to clean house and delete user accounts that are no longer necessary.

It can be just a little tricky to properly delete a user’s account, so I figure it’s something worth covering. The tool we’ll be using is ‘userdel‘ and my checking indicates it’s universal. Let’s get to it!

Delete A User:

I’m gonna assume that you already know the name of the user you’d like to remove from your system. With that information in hand, let’s open the terminal by pressing CTRL + ALT + T on your keyboard. 

Once you have the terminal open, you can do a basic user delete with:

If the user has a /home/user directory, you can delete that at the same time with this:

Seems nice and easy, right? Well, before you should run any of those commands you should be sure that the user is both not logged in and has no processes running in their name. If you do have either of those things, you will want to run this command before running either of the userdel commands above:

You can also try the -f (force) option with the userdel, but I’ve never had good luck with that. So, your better using killall before you use userdel. If you’d like to try it, here it is:

And that’s actually everything. There’s likely to also be a graphical way to delete users and that’ll depend on your desktop environment. Rather than play around with learning and documenting all those, you can just do it in the terminal where it’s easy enough and equally effective.

Closure:

And now you know how to delete a user account, and how to do it properly. Indeed, this is another article in the books and hopefully this one will help people for years to come. It’s a good idea to not have pointless users around on your system. If they exist, they can be used.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Subscribe To Our Newsletter
Get notified when new articles are published! It's free and I won't send you any spam.
Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.