Ubuntu is a popular open-source operating system based on the Linux kernel. It is widely used on personal computers, servers, and in cloud computing environments. One of the key tasks in managing a Ubuntu system is managing users and groups. In this article, we will explain how to add and delete users in Ubuntu 22.04.
Before we begin, it is important to note that in Ubuntu, only users with administrative privileges (also known as “root” users) can add and delete other users. If you do not have administrative privileges, you will need to ask an administrator to perform these tasks for you.
Adding Users in Ubuntu
`adduser` command in Linux is used to create a new user in the system. It is typically used with the following syntax:
<comment>## Syntax </comment>
adduser [options] username
Some common options that can be used with the
`user_name` command are:
-c:Specifies the user’s full name.
-d:Specifies the user’s home directory.
-g:Specifies the user’s primary group.
-G:Specifies a list of secondary groups that the user belongs to.
-m:Creates the user’s home directory if it does not already exist.
-s:Specifies the user’s login shell.
-u:Specifies the user’s UID (user ID).
To add a new user in Ubuntu, follow these steps:
- Open a terminal window by pressing
`Ctrl + Alt + T`or by searching for “Terminal” in the dashboard.
- Type the following command to add a new user, replacing the
`user_name`with the desired username:
sudo adduser user_name
- You will be prompted to enter a password for the new user. Enter a strong password and confirm it by retyping it.
- You will also be prompted to enter various personal information for the new user, such as the user’s name, phone number, and email address. You can leave these fields blank by pressing “Enter” if you do not want to provide this information.
- Once the user has been created, you can set additional user privileges using the
`usermod`command. For example, to add the user to the `sudo` group, which allows the user to perform administrative tasks, use the following command:
sudo usermod -aG sudo user_name
- You have successfully added a new user account in the Ubuntu system. See the below screenshot for the expected command output:
Let’s see another example with a few options, to create a new user with the username “tecadmin” , a home directory at “/var/home/tecadmin” , and the Zsh shell as the login shell, you could use the following command:
adduser -m -d /var/home/tecadmin -s /bin/zsh tecadmin
For a complete list of options and more information about the adduser command, you can consult the adduser man page by typing
`man adduser` in a terminal window.
Deleting Users in Ubuntu
To delete a user in Ubuntu, follow these steps:
- Open a terminal window as described above.
- Type the following command to delete the user, replacing
`user_name`with the username of the user you want to delete:
sudo deluser user_name
- You will be prompted to confirm the deletion. Type `Y` and press Enter to proceed with the deletion.
- If the user you are deleting has files in their home directory, you will be asked if you want to remove these files as well. If you want to delete the user’s files, type `Y` and press `Enter`. If you do not want to delete the user’s files, type N and press Enter.
Note: It is generally a good idea to back up any important files before deleting a user. Once a user and their files are deleted, they cannot be recovered.
In this article, we have explained how to add and delete users in Ubuntu 22.04. We have also discussed how to set additional user privileges using the usermod command and how to delete a user’s files during the deletion process. With these skills, you should now be able to manage users and groups on your Ubuntu system effectively.