How to Add/Remove additional users on Ubuntu 18.04


Adding and removing users on a Linux system is one of the most important system administration tasks to familiarize yourself with. When you create a new system, you are often only given access to the root account by default.

While running as the root user gives you complete control over a system and its users, it is also dangerous and can be destructive. For common system administration tasks, it is a better idea to add an unprivileged user and carry out those tasks without root privileges. You can also create additional unprivileged accounts for any other users you may have on your system. Each user on a system should have their own separate account.

For tasks that require administrator privileges, there is a tool installed on Ubuntu systems called sudo . Briefly, sudo allows you to run a command as another user, including users with administrative privileges. In this guide we will cover how to create user accounts, assign sudo privileges, and delete users.

Adding a User

While signed into root you can freely create new users at anytime using the command: adduser newuser, it will prompt you for a preferred password, and some additional information which is okay to just leave as is by pressing Enter on such options.

This will essentially create a new user with the group: newuser:newuser, and a new home directory in /home/newuser.

Allowing sudo privileges

To allow sudo privileges to the newly created user, we simply execute the command: usermod -aG sudo newuser adding it to the sudo group, allowing said user to run anything that requires sudo privs.

Deleting a user

To delete any user at any moment, we must run the command: sudo deluser newuser, to have it delete the users home directory and files, we must provide the --remove-home flag as such: sudo deluser --remove-home newuser

There you go, now you know how to create new users, delete them, as well as make users allowed to run the sudo command.