Add and Delete Users on Debian 11


Prerequisites:

You need to be logged in as root or a user with sudo access to be able to add and delete users on your Debian system.

How to Add Users:

There are two commands for adding users in Debian, useradd and adduser. useradd is a low-level tool for adding users while adduser is user-friendly interactive frontend to useradd written in Pearl.

To create a new user account named username using the adduser command run:

$ sudo adduser username
Output

Adding user `username' ...
Adding new group `username' (1003) ...
Adding new user `username' (1003) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...

You will be asked a series of questions:

Output

New password:
Retype new password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
	Full Name []:
	Room Number []:
	Work Phone []:
	Home Phone []:
	Other []:

And finally confirm or deny if the information you provided is correct:

Output

Is the information correct? [Y/n] y

The command will create the new user’s home directory, and copy files from /etc/skel to the user’s home directory. Within the home directory, the user can write, edit, and delete files and directories.

By default on Debian, members of the group sudo are granted with sudo access.

If you want the newly created user to have administrative rights, add the user to the sudo group:

$ sudo usermod -aG sudo username

How to Delete Users:

If the user account is no longer needed, you can delete it either with userdel or deluser. On Debian, you should usually use the deluser command as it is more friendly than the low-level userdel.

To delete the user without removing the user files, run:

$ sudo deluser username

If you want to delete the user, its home directory and mail spool, use the –remove-home flag:

$ sudo deluser --remove-home username

,