Managing users on Ubuntu

One of the first, most standard tasks to take care of on a freshly installed operating system is to add and/or remove users and assign privileges. In this tutorial you will learn how to do that on Ubuntu, a Debian-based Linux operating system for personal computers.

After a fresh install, you are often given the root account by default. This type of user is convenient because it gives you a lot of power and flexibility but in the long term, it is not secure. Therefore, it is recommended that you replace it with at least one additional, unprivileged user able to carry out standard tasks.

Adding a user

After signing in as root, you can create a new user at any time by typing:

adduser ingrid

As a non-root user with sudo privileges, you can add a new user by typing:

sudo adduser ingrid

The machine will execute your command and you’ll see some output, after which you will be asked to assign and confirm a password for the new user, as well as enter some additional information about the new user. Press Y to confirm the information.

Output

Adding new group `ingrid' (1001) ...
Adding new user `ingrid' (1001) with group `ingrid' ...
Creating home directory `/home/<^>ingrid' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for ingrid
Enter the new value, or press ENTER for the default
        Full Name []: Ingrid Tompson
        Room Number []: 235
        Work Phone []: 555-555-5555
        Home Phone []:
        Other []:
Is the information correct? [Y/n] y


As seen above, the adduser command created a user, a group, and a home directory for your user.

 

Granting sudo privileges

To grant sudo privileges to your newly created user, you must add it to the sudo group, like so:

usermod -aG sudo ingrid

 

Deleting a user

Finally, you’ll learn how to delete a user when necessary.

If you are logged in as root, you can simply type in this command:

deluser ingrid

In case you wish to delete the user’s home directory, enter the following command as root:

deluser --remove-home ingrid

Finally, in case you have configured sudo privileges for the user you deleted by editing the /etc/sudoers file, you can remove the relevant line in the file by typing:

visudo

 

And that is all! You have learn how to manage users on Ubuntu!

 

Leave a Reply