When using a Linux system, it’s possible to have numerous users accessing the same system. As the system admin, it’s your task to add and manage users on your Linux system. The newly created users don’t have admin privileges, but you can adjust the privileges based on what tasks the user was created to handle. This post focuses on what steps and commands you should use to add and delete users on Ubuntu 20.04. Let’s begin!
How to Add Users on Ubuntu 20.04
When you install Ubuntu 20.04, you, by default, become the root user. However, running commands as root exposes different risks, especially in messing up the system, as the administrative commands you can run can accidentally be destructive, especially if you are a new and inexperienced user.
Again, it could be you are sharing your Ubuntu 20.04 with someone else and want to create a new user for them. The benefit is that you can regulate the new user’s authority and monitor the unprivileged user’s activities.
When running commands as root, you don’t need to add the sudo keyword. However, even after being given administrative privileges, any other user must add sudo before an administrative command they want to run. That way, they must first enter their password to confirm their actions.
Creating a new user in Ubuntu 20.04 is easy. We will use the adduser command and then specify the username for the new user.
Let’s create “user1” for this example. We are adding sudo to give us administrative privileges to create the new user since we are not running as root.
Enter your password to authenticate that you want to add a new user to your system. You will get an output like the one below showing that the new user has been created and added to the “user1” group. A home directory for the user has also been created.
You will then get prompted to add details for the new user. You can add the details or press ENTER with the default values. In the last prompt, press ‘ y’ to confirm that all details are correct and complete adding the new user.
That’s it. You’ve managed to add a new user in your Ubuntu 20.04 successfully. You can verify this by listing the groups available to that user with the syntax below.
The output confirms two things. First, it shows that we managed to add a new user to our Ubuntu 20.04. Secondly, it shows that the new user is unprivileged and has no administrative privileges.
You can opt not to give the new user administrative privileges, limiting what they can do on the system. For instance, they can’t run updates and other commands requiring administrative privileges.
Alternatively, you can give the user administrative privileges by adding them to the sudoers group. For that, run the below command.
If we recheck the groups command again, we get a different output, confirming that the user now has sudo privileges as they are in the users and sudoers groups.
Your New User Is Ready, And You Can Use The Su Command To Switch To That User And Perform Any Task.
For instance, we can verify that the new user has administrative privileges by running the ls command with sudo to see what prompt we get. If we didn’t have administrative privileges, we would get an error and a warning.
How to Delete Users on Ubuntu 20.04
Deleting a user on Ubuntu 20.04 is straightforward. Run the deluser command as root or with sudo, then specify the target user you want to delete, as in the example below.
We are adding the –remove-home to help clean up the system by removing the user’s group and home directory.
With that, you’ve deleted the user, and even when you try switching to their account, you get an error showing that the user doesn’t exist.
That’s how to add and delete users on Ubuntu 20.04 with simple steps.
Conclusion
A common task in a Linux system, especially if you are the admin, is to add and delete users. In the case of Ubuntu 20.04, we’ve seen the simple steps you should take to add and delete users quickly. The steps are straightforward; anyone can easily follow along and understand what commands to add and delete users on Ubuntu 20.04.