Quick Links
Summary
To create a new user named “maxn” in Ubuntu, use the command “sudo adduser maxn”. To delete the user and their home directory, you want the “deluser –remove-home maxn” command. You can also add them to groups (usermod), reset their passwords (passwd), or give them sudo privileges (visudo).
The system administrator role includes creating users, deleting users, and reviewing existing users. They also control who can, and cannot, useroot’s elevated powers. Here’s how to do that on Ubuntu Linux.

What to Know About Managing Users in Ubuntu
Multi-user systems require a distinct user account for each person who uses the computer. Each users has their own password, and their own private area for data. Normal users cannot access another user’s data.Therootusercan access anything, of course.
It’s the root user who manages user accounts. They must create an account when a new user needs to use the computer, and they delete old accounts when they’re no longer required.

Apart from creation and deletion, other changes may be required during the lifetime of the account. The user may forget their password, and need it to have it reset. They may join another department or team and need to be added to the appropriate user group. They may even be promoted and be awarded root privileges.
These common tasks fall on the system administration team. If you’re the administrator on duty—or the only one in the team—you’re expected to complete these tasks quickly and easily.

Here’s a round-up of how to carry out these common tasks on Ubuntu. Because they use standard tools, you’re able to use them on other distributions too, but we’ll be featuring Ubuntu in the screenshots.
How to Create a User in Ubuntu
There’s two built-in command line methods ofcreating new users. They have very similar names, one isuseradd, and the other isadduser.
Theuseraddcommand needs all the information required to create the new account to be provided on the command line. Theaddusercommand takes a different approach. It prompts you for the information it needs to create the new account.

Using useradd
To add a new user withuseradd, use a command in this format.
The options and parameters we used are:

That creates the user, but we still need to set their password. We do this by passing the account login name to thepasswdcommand.
You’re prompted for the new password, which you must enter twice.

Using adduser
To add a new user with theaddusercommand, we provide the login name of the account we’re going to create.
You’re prompted for the password, and the full name of the new user.

If you want, you can hit “Enter” when you’re prompted for the optional “Full Name”, “Room Number”, “Work Phone”, “Home Phone”, and “Other” fields. These will be left blank.
How to Add a User Group in Ubuntu
Usually, when you’readding a user to a group in Linux, you’re actually adding them to an additional group. The group must already exist.
We do this using theusermodcommand. The important thing is to verify you use the-a(append) option together with the-G(supplementary group) option. If you don’t, the user is made a member of the new group, but their other group memberships are removed.

This’ll cause a lot of problems, because they won’t be a member of their own primary group and they won’t be able to access their own files—if they’re even able to log in.
To addmaxnto the development group, we use the-a(append) and the-G(supplementary group) options with the name of the group we’re adding them to. We’ll use thegroupscommand before and after, so that we can see what changes were made.

As we can see, the usermaxnhas been added to the “development” group, and he remains a member ofhis other groups, too.
How to List Users in Ubuntu
Keeping track of user accounts is part of the administrator’s role, too. Thankfully reviewing thelist of existing user accountsisn’t a problem, and there are several ways to do it.
We can use less to look inside the “/etc/passwd” file, but that shows all of the system and process “user” accounts as well as those used by actual, organic people.

All user accounts have a unique, numerical ID. The lowest and highest values that can be used as an ID are stored in the “/etc/login.defs” file. If we discover those values we can list the accounts that have values between these two limits. That’ll list the genuine user accounts for us.
To find out the upper and lower limits, we’llusegrepto search through the “/etc/login.defs” file. We’re searching for lines that start with either “UID_MIN” or “UID_MAX.”
On this computer the range of user account IDs is from 1000 to 60000.
Armed with this knowledge we can use thegetentcommand to search the password databases for entries with values in the range from 1000 to 60000.
That’s much more useful but, because it’s checking 59,000 user IDs, it does take a while to run. We can reduce that time by finding out the highest used user ID, and searching up to that value.
We’ll usethecutcommandand use the colon “:” as the field delimiter. We’ll extract the third field from the “/etc/passwd” file, which is the user ID field. We’ll pipe the output throughsort, and use the-g(general numerical sort) option to display the results in ascending numerical order.
Anything between 1000 and 60000 is a valid human account. The highest value on this computer that meets those criteria 1003. Slotting that value into ourgetentcommand speeds things up dramatically.
How to Add a User to sudo on Ubuntu
Those few users who are able to use thesudocommand are all members of a particular group. Toawardsudoprivileges to someone, you must add them to that group. On Ubuntu—and many other distributions—the name of that group is “sudo” but it might be something else, like “wheel”, so it’s best to check.
Thesudo visudocommand opens an editor and loads the “/etc/sudoers” file. Scroll down until you see an entry similar to “Allow members of group sudo to execute any command” and take a note of the group name.
In our case, it is “sudo.”
We’ll add usermaryqto that group, using theusermodcommand that we used earlier.
The next time Mary logs in, she’ll be able to use thesudocommand.
If the user has a specific need forsudoand no more, giving them unlimited access tosudois overkill. Let’s say Max needs to be able to install software usingtheaptcommand, but doesn’t need fullsudoaccess.
We need to add him to the “/etc/sudoers” file, and specify the command he can run withsudo.
Scroll through the file and insert these lines just above the last entry in the file.
The first line is a comment. The second line starts with the name of Max’s default user group. This usually matches the user’s login name. The “ALL=” means this applies all hosts on this network. The “(root)” means members of the “maxn” group can assume root privileges for the named commands, and the only named command is “apt.”
Note that there’s a Tab immediately after “maxn”, not a series of spaces.
Save your changes. When Max next logs in he’ll be able to run theaptcommand withsudo. He won’t be able to usesudowith any other command.
How to Change a User Password on Ubuntu
Changing a user’s passwordis easy. You’ll need to usesudowith the passwd command.
You’re asked to enter the password twice to ensure it is typed correctly. The next time the user logs in, they’ll need to use their new password.
If you don’t want to pick the user’s password, use the -e (expire) option. Thisforces the user to choose their own new passwordthe next time they log in.
How to Remove a User on Ubuntu
Ubuntu and other Debian-derived distributions have thedelusercommand toremove a user from your system. Distributions that are not based on Debian use theuserdelcommand instead.
Before you use the nuclear option, do you really want to delete them? You could just lock them out. That leaves you free to review their files and so forth.
If you’re determined to delete them but might want to refer to their files and data, archive their home directory using a tool such astar.
Let’s use Max’s user accountmaxnas an example.
To lock him out we can use thepasswdcommand with the-l(lock) option.
To archive his home directory we’llusetar.
Note there’s no hyphen “-” before the command line options totar. We used:
The archive file is created for us, with our requested name.
To perform the deletion of the user, we’ll use the–remove-homeoption to clear out their data at the same time.
From Cradle to Grave
As a system administrator you’ve got complete power over regular users. From creating them, managing them, and ultimately deleting them, the command line lets you do it all.