User Management on Ubuntu Linux

Mustafa AK
Clarusway
Published in
4 min readMar 26, 2021

In this article, we will look at mainly how to manage users on Ubuntu Linux.

  1. First of all, we will try to add users on Linux. We can use two commands for this purpose.
useradd
adduser

Let’s add a user called Marcus, and see all details about the new user using chage command.

sudo useradd marcus
sudo chage -l marcus

Our user is created but we need to set the password for him.

sudo passwd marcus

We have successfully set the password to Marcus and switched the user. But we did not create a home directory for Marcus. Normally we can add a home directory, using -m flag, but now we will use the below command to create a home directory for marcus.

sudo mkhomedir_helper marcus

2. Let’s try the first way to create a home directory at the same time as creating the user.

sudo useradd -m joseph

Now we will learn how to add a new user with his full name. Using the finger command we can see all details about the user linus.

sudo useradd -m -c "Linus Torvalds" linus

3. Now we will define an expiry date for our user using -e flag. I have created a new user called Fernando and set his expiry date as the first of April 2021.

sudo useradd -e <mm/dd/yyyy> <user_name>

4. When we create a new user, Linux automatically assigns a user id (UID) to a newly created user. we can also assign a user id manually using useradd command.

id    #shows current user_id
id joseph # shows designated user_id
sudo useradd -u 1007 micheal

5. In a Linux environment there are different types of shell. We can disable the user’s shell access. In this example, I have created a user named maria and defined sh shell for her. When I switched the user, I launched sh shell for maria.

sudo useradd -s /bin/sh maria   #define sh shell for maria
sudo usermod -s /bin/false maria #restrict maria to launch shell

6. Now we will look at usermod command. When we need to modify any information about a user, we use this command. For example, we can modify one of our user’s full names. There are also various options with that command.

sudo usermod -c "Linus Torvalds-mod" linus

7. We can lock down the user account using -L flag.

sudo usedmod -L marcus

8. Finally we will look at how to delete a user account.

sudo userdel marcus     #just delet user
sudo userdel -r marcus #delete user and his home directory

If we use useradd command to add a new user, the system asks for all information about the new user. We should enter all information while creating the user.

sudo adduser marcus

--

--

Mustafa AK
Clarusway

DevOps Engineer @ relayr | 2 x AWS and 2 x Azure Certified Cloud Engineer | Terraform | CKA | CKAD