Add and Remove Users on Ubuntu 20.04 - How to perform this task ?

One of the several duties of a Linux administrator is to manage the user accounts which also includes adding and removing the users. 

In Linux OS, a user can be added through either the command line and the GUI. 

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Linux related queries.

In this context, we shall look into how to add and remove users on Ubuntu OS.


How to add and remove users on Ubuntu system ?

Here, you will learn the following tasks:

1. Adding a user through command line

2. Removing a user through command line

3. Adding users through GUI

4. Removing users through GUI


1. How to add a User through Command Line ?

i. To add a user through command line is very simple. You can open the command line in Ubuntu through the Ctrl+Alt+T shortcut.

ii. To add a new user on Ubuntu, run the command in Terminal using the following command syntax:

$ sudo adduser <username>

Replace <username> with the actual user name you want to create on your Ubuntu system.

iii. After executing the adduser command, you will be prompted for the sudo password. Provide the password for sudo. After that, type a new password for the user and then type it again to confirm.

Then you will be prompted to enter more information for the user account. You can enter new values or simply hit Enter to accept the defaults.

In the end, you will be asked if the information is correct. Press y to continue, after which the new user account will be created on your system.

After creating the new user account, you can also grant it sudo privileges.

To grant sudo privileges to the newly created user account, you will need to add that account to the sudo group.

iv. Execute the following command in Terminal to add the newly created user account to the sudo group:

$ sudo usermod -aG sudo <username>

Replace <username> with the actual user name you want to create on your Ubuntu system.

This command will add the specified user to the sudo group which can be verified using the following command:

$ groups <username>


2. How to remove a User through Command Line ?

In case you need to remove a user account from your system, you can do so by using the following command in Terminal:

$ sudo deluser <username>

The above command will remove the user account from your system.

However, it does not remove the Home directory of the user account.

Alternatively, if you want to remove the user account as well as its Home directory, run the following command in Terminal:

$ deluser --remove-home <username>


3. How to add a User through GUI ?

For the users who are not comfortable working with the command line, here is how they can add users graphically.

i. You can add a user account in Ubuntu through the Settings utility

ii. You can open the Settings utility by right-clicking the Ubuntu desktop and selecting Settings.

iii. From the left pane in the Settings utility, go to the Users tab.

iv. In the right pane, Click the Unlock button to change settings.

v. Now provide your password for authentication and next click the Authenticate button. After that, the settings will be unlocked and you will be able to create a new user.

vi. Now in order to add a new user account, click the Add User button located at the top of the Settings window.

vii. Now the following dialog will appear on your screen.

For the Account Type, select Standard or Administrator based on what type of access you want to grant to the new user.

Then enter the Full Name and it will fill the Username field automatically.

viii. After that, you can choose to allow the user to set the account password itself when the next time it logins, or you can set a password at the current time by selecting the Set a password now radio button and entering the password twice.

ix. Once done with the configurations, click the Add button to create the user.


How to remove a User through GUI ?

i. To remove a user through GUI, open the Settings utility by right-clicking the Desktop and selecting the Settings option. 

ii. Then from the left panel in the Settings utility, go to the Users tab.

iii. Then click the Unlock button to change settings. 

iv. After that, provide your password for authentication and next click the Authenticate button.

v. After that, the settings will be unlocked and you will be able to modify the settings.

vi. Now select the user account you wish to remove from your system and click Remove User.

vii. Now the following dialog will appear asking you if you want to keep or remove the user account files including the user's Home directory. 

If you want to keep them, click Keep Files, otherwise click Delete Files to remove the user along with its Home directory.


[Need urgent assistance in fixing Ubuntu related packages installation? We are ready to help you today. ]

This article covers how you can add and remove users on Ubuntu and assign them administrator privileges. Based on your convenience, you can either choose to add and remove users either through the command line or GUI. 

Ubuntu, like any other Linux distribution, is a multi-user operating system. Each user can have different permission levels and specific settings for various command-line and GUI applications.

Knowing how to add and remove users is one of the basic skills a Linux user should know.


To add a user in Ubuntu via GUI:

1. Open the Activities overview and start typing Users.

2. Click on Users to open the panel.

3. Press Unlock in the top right corner and type in your password when prompted.

4. Press the + button, below the list of accounts on the left, to add a new user account.


To remove a user from Ubuntu:

1. Open the terminal app.

2. Login to server using the ssh user@server-ip-here command.

3. Run sudo deluser --remove-home userNameHere command to delete a user account on Ubuntu.

4. Verify it by running id command.


To Remove a Linux user:

1. Log in to your server via SSH.

2. Switch to the root user: sudo su -

3. Use the userdel command to remove the old user: userdel user's username.

Optional: You can also delete that user's home directory and mail spool by using the -r flag with the command: userdel -r user's username.


To Add a User to Linux:

1. Log in as root.

2. Use the command useradd "name of the user" (for example, useradd linuxapt)

3. Use su plus the name of the user you just added to log on.

4. "Exit" will log you out.


Linux operations commands:

1. adduser : add a user to the system.

2. userdel : delete a user account and related files.

3. addgroup : add a group to the system.

4. delgroup : remove a group from the system.

5. usermod : modify a user account.

6. chage : change user password expiry information.


How do I assign a user to a group in Linux?

1. To create a new group, enter the following: sudo groupadd new_group.

2. Use the adduser command to add a user to a group: sudo adduser user_name new_group.

3. To delete a group, use the command: sudo groupdel new_group.

4. Linux comes with several different groups by default.

Related Posts