Adding and deleting users is one of the most basic tasks when starting from a fresh Debian 10 server.
Adding user can be quite useful. As your host grows, you want to add new users, assign them special permissions, like sudo rights for example.
In this tutorial, we are going all the ways to add and delete users on Debian 10 hosts.
In order to add and delete users on Debian, you need to have sudo rights, or to belong to the sudo group.
If you are not sure about how to add a user to sudoers, make sure to check the tutorial we wrote about it.
To check your sudo rights, run the following command
$ sudo -v
If no error messages appear, you are good to go, otherwise ask your system administrator to provide you with sudo rights.
Adding a user using adduser
The first way to add users on Debian 10 is to use the adduser command.
The adduser command is very similar to the useradd command. However, it provides a more interactive way to add users on a Debian host.
Generally, it is preferred to use adduser rather than useradd (as recommended by the useradd man page itself)
To add a user, run this command
$ sudo adduser ricky Adding user 'ricky' Adding new group 'ricky' (1007) Adding new user 'ricky' (1005) with group 'ricky' Creating home directory '/home/ricky' Copying files from '/etc/skel'
You will be asked to choose a password for the user
New password: <type your password> Retype new password: <retype your password> Changing the user information for ricky
Then you will be asked to specify some specific information about your new user.
You can leave some values blank if you want by pressing Enter.
Enter the new value, or press ENTER for the default Full Name : Room Number : Work Phone : Home Phone : Other :
Finally, you will be asked if the information provided is correct. Simply press “Y” to add your new user.
Is the information correct? [Y/n] Y
Now that your user was created, you can add it to the sudo group.
Adding a user using useradd
$ sudo useradd <username>
To assign a password to the user, you can use the -p flag but it is not recommended as other users will be able to see the password.
To assign a password to a user, use the passwd command.
$ sudo passwd <username> New password: Retype new password: passwd: password updated successfully
Add a user using the GNOME desktop
If you installed Debian 10 with GNOME, you can also create a user directly from the desktop environment.
In the Applications search bar, search for “Settings”.
In the Settings window, find the “Details” option.
Click on “Details”, then click on “Users”.
On the top right corner of the window, click on “Unlock”.
Enter your password, and a “Add User” option should now appear in the panel.
In the next window, choose what type of account you want for the user (either with sudo rights or not).
Fill the full name field, as well as the username field.
You can choose to assign a password now or you can let the user decide on its password on its next logon.
When you are done, simply click on “Add”.
Congratulations, your account was successfully created.
Check that your user was added
In order to check that your user was created on Linux, run the following command.
$ cat /etc/passwd | grep <user> <user>:x:1005:1007:User,,,:/home/user:/bin/bash
If there are no entries for the user you just created, make sure to use the adduser command again.
Deleting a user using deluser
In order to delete a user on Debian 10, you have to use the deluser command.
$ sudo deluser <username>
To remove a user with its home directory, run the deluser command with the –remove-home parameter.
$ sudo deluser --remove-home <username> Looking for files to backup/remove Removing user 'user' Warning: group 'user' has no more members. Done.
To delete all the files associated with a user, use the –remove-all-files parameter.
$ sudo deluser --remove-all-files <username>
Deleting a sudo user with visudo
If you removed a sudo user on Debian, it is very likely that there is a remaining entry in your sudoers file.
To delete a user from the sudoers file, run visudo.
$ sudo visudo
Find the line corresponding to the user you just deleted, and remove this line.
<username> ALL=(ALL:ALL) ALL
Save your file, and your user should not belong to the sudo group anymore.
Deleting a user using the GNOME Desktop
From the users panel we used to create a user before, find the “Remove user” option at the bottom of the window.
Note : you need to unlock the panel to perform this operation.
When clicking on “Remove User”, you are asked if you want to keep the files owned by this user. In this case, I will choose to remove the files.
In some cases, you may have some error messages when trying to execute some of the commands above.
adduser : command not found on Debian
By default, the “adduser” command is located in the “/usr/sbin” folder of your system.
$ ls -l /usr/sbin/ | grep adduser -rwxr-xr-x 1 root root 37322 Dec 5 2017 adduser
To solve this issue, you need to add “/usr/sbin” to your $PATH.
Edit your .bashrc file and add the following line
$ sudo nano ~/.bashrc export PATH="$PATH:/usr/sbin/"
Source your bashrc file and try to run the adduser command again.
$ source ~/.bashrc $ sudo adduser john Adding user `john' ... Adding new group `john' (1001) ... Adding new user `john' (1001) with group `john' ... Creating home directory `/home/john' ... Copying files from `/etc/skel' ...
You solved the “adduser : command not found” problem on Debian 10.
As you can see, adding and deleting users on Debian 10 is pretty straightforward.
Now that your users are created, you can also set up SSH keys on Debian 10 for a seamless authentication.