Overview

The following article will demonstrate the steps on how to create a user in Ubuntu. Also, we’ll be demonstrating how to delete user in Ubuntu and all actions we’ll be executed in terminal.

Knowing how to create a user in Ubuntu and how to delete a user is one of the basic skills a Linux user(admin) should know and still one of the most important skills as well to have(user management). Reason behind this is, because in every multi user operating system(Linux as well) there are and there should be a sets of different user permissions and different user groups. This is because of security reasons.

You don’t want to have one user managing the entire system which runs on a production environment(meaning on servers). It’s always advisable to have multiple users on your system. Sometimes you might need to have a user will act only as a service account(not having a home folder, no access to the shell and only be able to run specific apps and tools).

The commands we’ll be using to run these actions are - “adduser” and “deluser”. You can also create a new user with the command - “useradd”. There are differences between these two commands. They behave differently and will cover both of them.

Next in line of user management skills is how to create user groups and to add user to a groups(and of course remove user from group and delete group). You can check out this procedure as well on this post - LINK.

Prerequisites:

To be able to add user in Ubuntu and remove user, you need to be logged in as root or as a user with sudo privileges.

How to create a user in Ubuntu

Create a user with adduser command

We’ll first create a new user with the “adduser” command. The “adduser” command will create a new user with a home directory automatically, and ask to set the password for the new user as well, create a default user settings(adding user details in /etc/passwd file, add a unique user ID, etc). Once you are in a terminal to create a new user you will type “adduser” and it’s “username”. You will be asked for your sudo password.

sudo adduser newuser

Once you type your password , you will be asked series of questions , from which password is needed for the new user ,and all other questions are optional.

create a user in Ubuntu

After you will just need to confirm the information with “y”. And you have successfully created a new user. This command will also create a new users home directory.

Also to put in your mind that in Ubuntu by default members of the sudo group are granted with sudo access. Meaning, the newly created user will not be in the sudo user group by default and you’ll need to add it.

Create a user with useradd command

When you create a new user with the command “useradd”, it will just create an “empty” user. It will not have a home directory, it will not have a password set and not be a part of any user groups. That means, after the user creation with the “useradd” command you’ll need to set everything separately.

sudo useradd newuser2

There are of course options for this command which can add and set other user settings that are needed. For an example, if you need to a have a home directory for a new user, you then need to add the option “-m” on the “useradd” command. The command looks like this:

sudo useradd -m newuser2

create a user in Ubuntu

After the user creation with the “useradd” command, the user won’t be able to login since it doesn’t have a password set(the command doesn’t set it). The password can easily set with the command “passwd”.

sudo passwd newuser2

We can say, essentially if you need a to create a user in Ubuntu quickly with one command, with a home directory, password and everything else desktop user has, use the - adduser command. For more control and user management on servers, better to go with useradd command.

For more options and information how to set other user settings, you can reffer to the man pages of both commands - adduser , useradd

Add sudo privileges to a new user

To add the sudo permission to the new user, we use the “usermod” tool to modify the user. The tool needs to be run with sudo. Run the command like this:

sudo usermod -aG sudo newuser

create and delete users in ubuntu

How to delete a user in Ubuntu

For this action you will use command “deluser” and type it’s “username”. For this command as well you need to run it with sudo or either run as root.

sudo userdel newuser

After you type in the sudo/root password - the user and it’s settings will be deleted, but it’s home directory and files won’t be deleted. To delete a user with it’s home directory all together at once, add the “-r” option in the command. The command will look like this:

sudo userdel -r newuser

create and delete users in ubuntu

Summary

Now you have mastered the process on how to create a user in Ubuntu and how to delete a user. To summarize the steps we performed the following - created a user with “adduser” command, created a user with “useradd” command(with the user home directory) and deleted users as well alongside their home directory.

Also to point out that all commands that we have used in this article, can of course apply in any Ubuntu-based distribution, and other distributions as well such as Debian, Kubuntu, Pop OS and Linux Mint.

Thank you for your time…