Managing users is a fundamental task for system administrators working with Ubuntu or Debian. This guide explains how to add new users, remove unwanted accounts, and change user passwords using simple commands. Additionally, it covers initial operating system requirements and best practices to help you maintain secure and well-organized user access on your Linux servers.
Initial Debian System Requirements
Many of the commands in this guide require superuser privileges. If the following error appears when using the sudo command:
bash: sudo: command not found
You need to activate superuser mode, install the sudo command, and add your user to the sudo group:
su -
apt-get install sudo -y
usermod -aG sudo yourusername
How to add a new user?
Ubuntu and Debian have two command-line tools that you can use to create a new user account: useradd and adduser.
useradd is a low-level utility for adding new users, and adduser is a friendly interactive interface for useradd written in Perl.
To create a new operating system user account named username using the adduser command, run the following command:
sudo adduser username
As a result, a dialogue appears in which you must enter the password and additional information:
Adding user `username' ...
Adding new group `username’ (1000) …
Adding new user `username’ (1000) with group `username’ …
Creating home directory `/home/username’ …
Copying files from `/etc/skel’ …
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 []: Name
Room Number []: 100
Work Phone []: 123-45-45
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
The command creates the home directory for the new user and copies the files from the /etc/skel directory there.
By default, sudo members are granted sudo access.
If you want the newly created user to have administrator rights, add him to the sudo group:
sudo usermod -aG sudo username
How to delete a user?
There are two command-line tools that you can use to delete a user account: userdel and deluser. We recommend using the deluser command, as it is more friendly than the low-level userdel.
To delete a user without deleting user files and directories, do:
sudo deluser username
If you need to delete the user's home directory and its contents, use the –remove-home flag:
sudo deluser --remove-home username
As a result, the following message appears:
Looking for files to backup/remove ...
Removing files …
Removing user `username’ …
Warning: group `username’ has no more members.
Done.
How to change the user password?
To change your password, use the passwd command with no additional arguments:
passwd
In the system dialogue, you will need to enter the old password and specify a new one:
Changing password for username.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
To change the password for another user, you must have administrator rights and username:
sudo password username
Conclusion
User management is a critical skill for system administrators working with Ubuntu and Debian. In this guide, you learned how to add new users, delete existing accounts, and change user passwords using straightforward command-line tools like adduser, deluser, and passwd. You also explored how to grant administrative privileges by adding users to the sudo group. By mastering these commands and understanding initial system requirements, you can maintain secure and efficient user access control on your Linux servers.
FAQ - Frequently Asked Questions
- What is the difference between adduser and useradd?
adduser is a user-friendly interactive tool that simplifies user creation, while useradd is a lower-level command requiring more manual configuration. - How do I give a new user administrative (sudo) rights?
Add the user to the sudo group using:sudo usermod -aG sudo username
- How do I delete a user and remove their home directory?
Use the deluser command with the --remove-home flag:sudo deluser --remove-home username
- How can I change the password for another user?
Run the command:sudo passwd username
and enter the new password when prompted.
- What if the sudo command is not found?
Switch to the root user and install sudo, then add your user to the sudo group:su -
apt-get install sudo -y
usermod -aG sudo yourusername