Adding and managing user accounts in Ubuntu 18.04 LTS

User management becomes a critical factor when you want to add multiple users to the system. If managing users on your system is inefficient, you may need to compromise the security and access to the confidential and confidential information stored on your system. This article provides you with simple methods that you can use to effectively manage users. It includes user and group management procedures, both using the user interface and from the command line, which you can follow with the simplest steps.

We execute the commands and processes described in this article on Ubuntu 18.04. Please note that to perform any tasks mentioned here, you need superuser privileges. So, let’s first understand what is root?

Understanding the root user

Before you begin with user management, it is important to have an understanding of the root user in Linux. Ubuntu by default does not allow the root user to log in directly (although other Linux distributions, such as Debian and CentOS, allow direct root login); Ubuntu, therefore, created a feature called “sudo” that you can use to perform various administrative operations. You need to specify the password using the sudo command, which helps to control all user actions as an administrator. By default, the first user created during the installation of Ubuntu gets sudo privileges. He has been granted full superuser rights and is added to the sudoers list in the / etc / sudoers file.

It is important to note that you must be an authorized user to complete all user management operations described in this article.

user management

You can add users to Ubuntu through the user interface; however, preliminary user management must be done through the command line.

Add user via GUI

Please follow these steps to add a user via the Ubuntu GUI:

Open the Account Settings dialog box either through Ubuntu Dash, or by clicking the down arrow located in the upper right corner of the Ubuntu screen. Click your username and then select “Account Settings” as follows:

Add Ubuntu User via GUI

The following Users dialog box appears. Please note that all fields will be disabled by default. You will need to provide authentication for further work with this dialog. Press the unlock button located in the upper right corner of the Users dialog box.

Unlock user dialog

The following authentication dialog box will open you so that you can provide authentication information on behalf of the administrator, because this is the only way you can create or edit user accounts:

Confirm that you have administrator rights on this computer

Please enter your password and then click Authenticate button. Now you can see that all the fields in the “Users” dialog box are enabled for working with you:

Add user dialog

Press on Add user button. The following Add User dialog box opens to enter information about the new user you want to create:

Create a standard or administrative user

In this dialog box, you can specify whether you want to create a regular or administrative user. It is also important to know that it is not recommended to leave the password field blank for a new user. Thus, any user can log into the system and gain access to personal and protected data in your system.

Press on add A button that will be enabled only when you have provided all the valid information in the Add User dialog box.

A new user will be created, and you will be able to see him in the “Users” dialog box as follows:

List of Linux users on Ubuntu

Adding a user through the command line

The Ubuntu command line gives you more administrator privileges to perform user management operations. Please follow these steps to add a user through the command line:

  1. Open a terminal by pressing Ctrl + Alt + T or through Ubuntu Dash.
  2. Enter the following command to add a new user:
$ sudo adduser [username]

Add user using adduser command

You will need to enter a password for sudo. You will also be prompted to enter and re-enter the password (for re-confirmation) for the new user. You can provide or ignore the bio-entry of a new user, as this is optional.

To come in Y if the information you provided is correct, then press Enter.

A new user will now be created on your Ubuntu system.

List all users

As an Ubuntu administrator, you can view the list of users added to your system with the following command:

$ awk -F':' '$2 ~ "$" {print $1}' /etc/shadow

List all users in the shell

In this image, sana is the administrator, guest is the user we created using the user interface, and guest guest is the user we created using the command line.

Lock / Unlock User Accounts

Ubuntu allows you to temporarily lock and unlock any user account using the following commands:

$ sudo passwd -l username
$ sudo passwd -u username

A blocked user cannot log in until he / she is in a locked state.

Granting root rights to a user

If you want to give the user root privileges, you will need to edit the visudo file that contains the list of sudoers on your system.

Open the visudo file with the following command:

$ sudo nano visudo

This command will open the visudo file in the Nano editor.

Add the following lines to the file:

[username] ALL=(ALL) ALL

This line will grant full root privileges to the specified user.

User_Alias ADMINS = [username]

Cmnd_Alias HTTPD = /etc/init.d/httpd

ADMINS ALL = HTTPD

These lines will create a user group to which you can assign command aliases.

Visudo File Contents

Exit the file using Ctrl + X, then type Y and Enter to save the changes made to the visudo file.

The user ‘guest’ from our example will now be able to perform all root operations.

Removing a user through the command line

You can delete the user through the command line using the following command:

$ sudo deluser [username]

Delete user via command line

In this example, we deleted the guest user. Remember that if a user is removed from a group that no longer has members, this group will also be automatically deleted.

Removing a user through a graphical interface

You can perform the simple task of removing a user through the graphical interface as follows:

  1. Open Account settings a dialog box either through the Ubuntu dash or by clicking the down arrow located in the upper right corner of the Ubuntu screen. Click on your username and select “Account Settings”.
  2. User dialog will open. Please note that all fields will be disabled. You will need to provide authentication for further work with this dialog. Press on unlock The button is located in the upper right corner of the Users dialog box.
  3. Select the username you want to remove and click Delete user Button as follows:

Uninstall Ubuntu User via GUI

You will be asked if you want to delete or save deleted user files from your system in the next dialog box.

Choose whether you want to save user files

You can delete or save files using the corresponding buttons. Then the user will be removed from your system.

Deleting / archiving the home folder of a remote user

When you delete a user from your system, his home folder may still be on your computer, depending on the choice you made when deleting the user. You can delete this folder manually or archive it. The new user that you create with the same user ID or group ID as the remote user will now be able to access your folder. You might want to change these UID / GID values ​​to something more suitable, such as a root account. You can even move the folder to avoid future conflicts with the following commands:

$ sudo chown -R root:root /home/username/
$ sudo mkdir /home/archived_users/
$ sudo mv /home/username /home/archived_users/

Group management

Ubuntu allows you to create groups for users on your system. Thus, you can assign administrative rights and access to files to the entire group, and not to one user at a time.

You can perform group management in Ubuntu 18 only through the command line.

Adding a Group

To add a new user group, enter the following command:

$ sudo addgroup [groupname]

Example:

Add Linux Group

A new group will be created and it will be assigned a unique group identifier (GID).

Adding users to a group

You can add an existing user to the group with the following command:

$ sudo adduser [username] [groupname]

Example:

Add user to group

View Group Information

To view group members, use the following command:

$ groups username

You can use the following command to list the group members along with their GID

$ id username

View Group Information

The gid output represents the main group assigned to the user. Please read on to find out what is the main and additional group.

Change the primary user group

A user may be part of one or more groups; one of them is the main group, and the others are secondary groups. In the output of the id command, gid indicates the primary user group. To change the primary user group, use the following command:

$ sudo usermod -g [newPrimaryGroup] [username]

Example:

Change the primary user group

Now you can see that the new gip file received with the id command corresponds to the newly assigned main group.

Group Assignment at User Creation

You can assign a group to a user at the same time when creating a new user as follows:

$ sudo useradd -G [groupname] [username]

Example:

Group Assignment at User Creation

Set or change password for user

Please note that no password has been assigned to this new user. This is not a good security practice, so you should assign a password to this new user as soon as possible with the following command:

$ sudo passwd [username]

Example:

Update user password

The new user will now have a password.

See the following UI image of how a user account was disabled by the system before it was assigned a password.

Login disabled if password not set

List of all groups

You can get a list of all groups on your system with the following command:

$ sudo getent group

Adding and managing user accounts in Ubuntu 18.04 LTS

Group deletion

To remove a user group from your system, you can use the following command:

$ sudo delgroup [groupname]

This article explains how you can manage users and groups on an Ubuntu system to effectively manage rights and privileges. You can manage users as an administrator or grant administrative rights to other users to perform these operations using the useful steps described in this guide.

Adding and managing user accounts in Ubuntu 18.04 LTS

Sidebar