Introduction
Debian is a multi-user operating system, as well as all other Linux distributions. For numerous command-line and GUI apps, each user might have varying permission levels and particular settings.
One of the fundamental abilities a Linux user should have is, the ability to add and remove users.
This tutorial describes how to add and remove users on Debian 9. We will also address a few FAQs on how to add and remove users on Debian 9.
Prerequisites
To add and delete users on your Debian system, you must be logged in as root or as a user with sudo access.
How To Add User on Debian
To create a new user account on Debian, you can use the useradd
and adduser
command-line programs.
adduser
is a nice interactive frontend to useradd written in Perl. useradd
is a low-level program for adding users.
To use the adduser command to create a new user account named username, type:
sudo adduser username
Output
Adding user `username' ...
Adding new group `username' (1001) ...
Adding new user `username' (1001) with group `username' ...
Creating home directory `/home/username' ...
Copying files from `/etc/skel' ...
A series of questions will be asked from you. All other fields are optional, except for the password.
Output
Enter new UNIX password:
Retype new UNIX 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 []:
Is the information correct? [Y/n]
You must enter Y
to confirm that the information is correct on the final prompt.
The command will create the new user's home directory and copy files from the /etc/skel
directory into it. The user can write, edit, and delete files and folders in their home directory.
Sudo access is allowed to members of the sudo group by default on Debian.
Add the newly formed user to the sudo group if you want the user to have administrative rights:
sudo usermod -aG sudo username
How To Delete a User on Debian
If you no longer require the user account, you can delete it using userdel
or deluser
. On Debian, the deluser
command is preferred over the low-level userdel
command because it is more user-friendly.
Run the following command to deactivate the user without deleting the user's files:
sudo deluser username
Use the --remove-home
flag to delete the user, as well as its home directory and mail spool. And to use that, you have to install the following package:
sudo apt-get install perl-modules
sudo deluser --remove-home username
FAQs to Add and Delete Users on Debian 9
How can I grant root privileges to a user on Debian 9?
To grant root privileges to a user, add the user to the sudo
group: sudo adduser username sudo
. This allows the user to use the sudo
command for administrative tasks.
What is the command to delete a user on Debian 9?
To delete a user from Debian 9, use the deluser
command followed by the username: sudo deluser username
. Be careful as this action is irreversible.
Can I specify additional user details during user creation?
Yes, you can provide additional user details during user creation using the adduser
command with options. For example, sudo adduser --gecos "John Doe,,,Mobile" username
allows you to specify full name, room number, work phone, and home phone.
How do I remove a user's home directory when deleting a user?
By default, the user's home directory is not removed when deleting a user on Debian 9. To remove the home directory along with the user, use the --remove-home
option: sudo deluser --remove-home username
.
Is it possible to disable a user account without deleting it?
Yes, you can disable a user account by locking it using the usermod
command: sudo usermod --expiredate 1 username
. This sets the account expiration date to the past, effectively locking the user out.
What is the difference between adduser
and useradd
commands?
The adduser
command is a user-friendly interface that simplifies the process of adding users, while useradd
is the actual low-level command used by adduser
for user creation. It's recommended to use adduser
for simplicity.
Can I specify a custom home directory path when creating a user?
Yes, you can set a custom home directory path during user creation using the -d
option with the adduser
command: sudo adduser -d /path/to/directory username
.
Conclusion
You learned how to add and remove users on Debian in this tutorial. Any Debian-based distribution can use the same commands.
If you have any queries, please leave a comment below and we’ll be happy to respond to them.