Introduction to Linux User Management under Ubuntu

User management is one of the most important tasks in an enterprise environment. Even a single system uses multiple users, not only for logging in, but also for running various applications. Even in a Linux environment, an administrative role is necessary for managing multiple user accounts, their credentials, and the security of the systems. The basic commands must be known to the Linux admin to manage these multiple user accounts (users and other subgroups).

In this tutorial, we will look at the basic Linux commands that may be needed in user management. We also show you how to do user management using Ubuntu Desktop

Creating a user account

As we all know, Linux is a multi-user operating system, which means that each user has his or her own user account that contains all the user’s data, including files and other information related to that user. The data and information related to a particular user should not be accessible to other users. There is also a possibility that a single system is shared by different users. Therefore, the system administrator should know how to create and manage different user accounts in a Linux environment. In this tutorial, you will learn how to create a user account using commands with Terminal:

Step 1: First of all, open Terminal by clicking on the Ubuntu launcher and search for Terminal.

Open the terminal to create a Linux user account

Step 2: Now click on the Terminal and wait for the terminal to open.

Open Terminal

Step 3: Once the terminal is opened, you will have a screen like this:

Terminal prompt is shown

Step 4: Now type the command:

sudo adduser username

where username will be the name of the user you want to create. Once typed, execute the command by pressing enter key. In the example, I am creating a user with the name demo1.

Create user with adduser command

Step 5: Once executed, the system will ask the password of a newly created user. Enter the password, confirm password and press enter. The password which you type will not be appear on the terminal screen so don’t worry about it.

Enter a password for the user

Step 6: Once the password is updated, the system will ask for the basic details of the user. You can enter the information related to that user or simply press “enter” to insert the default value.

Enter user details

Step 7: Once you enter all the information, the system will confirm that all the information entered is correct or not. Press ‘y’ to confirm. Once confirmed, the user has been created by the system.

Ubuntu Linux user has been successfully addedChange a Password

Many time situations occur user forget their password, so it is the job of the system administrator to reset the password for the user. Resetting password in Linux is pretty much easy. Below are the steps to change the password for a specific user.

Step 1: First of all, open Terminal by clicking on the Ubuntu launcher and search for Terminal.

Open terminal to change the user password

Step 2: Now click on the Terminal and wait for the terminal to open.

Open the terminal

Step 3: Once the terminal is opened, you will have a screen like this:

Terminal command prompt

Step 4: Now type the command

sudo passwd username

where username will be the name of the user whose password you want to update. Once typed, execute the command by pressing the enter key. In the example, I am modifying the password demo1.

Linux passwd command

Step 5: Once executed, the system will ask the user for a new password. Enter the password, confirm password and press enter. The password which you type will not appear on the terminal screen so don’t worry about it.

Passwd of Ubuntu user has been changed successfully

Your password has been updated successfully.

Delete a user account

At times in a shared environment where we have multiple users but if any of them leaves a particular group, then the administrator has an obligation to remove the old accounts from the system. Here is what you are supposed to do in case you need to delete an account.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Find the terminal

Step 2: Now click on the Terminal and wait for the terminal to open.

Start terminal application

Step 3: Once the terminal is opened, you will have a screen like this:

Terminal prompt shows up

Step 4: Now write the command

sudo userdel username

where username is “demo1”. Once, you press enter, the user will be deleted.

Use userdel command to remove a Linux user

Adding users to groups

One user can be assigned to a group and this grouping is helpful for applying any permission to entire group because it is applicable to all. So, it makes user management much easier. In this tutorial, I am going to tell how you can add the user into “sudo group”.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Open Terminal

Step 2: Now click on the Terminal and wait for the terminal to open.

Launch terminal app

Step 3: Once terminal is opened, you will have a screen like this:

Terminal started and ready for input

Step 4:  Now type the command

sudo usermod –a –G examplegroup username

where example group is the name of the group in which the user wants to be associated and username is the name of the user who wants to add into a group. Once typed, execute the command by pressing enter key. In the example, the group is “sudo” and the user is “demo1”.

Add Linux user to group

The user will be added to that group.

Setting the Expiry Date of an Account

To automatically expire the account, in Linux we can set expiry date, after which the account will no longer available to be used.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Find shell app

Step 2: Now click on the Terminal and wait for the terminal to open.

Launch Linux shell from Desktop

Step 3: Once the terminal is opened, you will have a screen like this:

Linux shell window ready for input

Step 4: Now write the command:

sudo chage –E YYYY-MM-DD username

where username is “demo1”. YYYY-MM-DD is the date at which you want the account to expire.

Use linux chage command

Once, you press enter, the expiry date of the account will be set and the account will expire after that date.

Changing the default location of the user’s home directory

You can also change the default location of a user’s home directory by following these steps.

Step 1: First of all, open Terminal by clicking on Ubuntu launcher and search for Terminal.

Find terminal program

Step 2: Now click on the Terminal and wait for the terminal to open.

Launch the program

Step 3: Once the terminal is opened, you will have a screen like this:

The Linux shell

Step 4: Now write the command

sudo usermod –d newuserhomedirectorypath –m username

where username is “demo1”, newuserhomedirectorypath is /home/demo1/Desktop in our sample example.

Use Linux usermod command

Once you enter this command, the default location of user’s home directory has changed.

Disabling Linux user account

Any account can be disabled by the administrator. Following are few easy steps for it.

Step 1: First of all, open Terminal by clicking on the Ubuntu launcher and search for Terminal.

Get the shell app

Step 2: Now click on the Terminal and wait for the terminal to open.

Launch shell app

Step 3: Once the terminal is opened, you will have a screen like this:

Ubuntu shell is ready

Step 4: Now write the command

sudo chage –E 0 username

where the username is “demo1”. Once, you press enter, the account will be disabled for that particular user.

Use chage command

In case you want to enable the disabled user, you need to run:

sudo chage –E 1 username

When you press enter, the account will be enabled once again for that user.

Enable user with chage command

Conclusion

In this tutorial, we have discussed the basic commands to create, add and delete a user, further we have discussed the steps to add a user to a particular group. After that, we have seen the steps to set the expiry date of a particular account. We have also seen a method to change the default location of a user’s directory. In the end, we have seen the command to enable/ disable a user’s account.

A Beginners Guide to User Management on Ubuntu Desktop and Server

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn