How to Add and Delete Users in Debian 12: Command Line

Managing users in Debian is a fundamental task for maintaining server security, organizing access control, and facilitating smooth operation within a multi-user environment.

Linux is a multi-user environment where two types of users are present: a superuser (root) and regular users. The superuser is granted unlimited administrative privileges, while regular users are granted specific permissions and restrictions to ensure unauthorized modifications are prevented on the Debian server. If you are a superuser, you can add, delete, or modify users in the Debian system and assign them proper permissions.

In this blog post, I will cover how to add users, set passwords for users, and delete user in Debian 12.

Prerequisites

Before adding a new user in Debian, you must meet the following requirements:

  • You are a superuser or have root permissions.
  • You have administrative privileges.
  • You have text editors like Nano or Vim.

How to Add a User in Debian

In Debian, there are several options available for adding a new user. You can utilize the adduser, useradd, or newusers command-line tools to accomplish this task.

Step 1: Switch to the Root User

Before proceeding with adding a user to the Debian system, it is recommended to switch to the root user. To do this, simply enter the following command in your terminal:

su -l

Step 2: Adding a User with the adduser Command

The adduser command is a recommended utility for adding users in Debian. It offers a straightforward way to specify a username, set a password, and provide additional details about the user. To add a user using adduser, execute the following command in your terminal:

adduser username

This command will create a user account with the name ‘username’ and prompt you to enter a password as well as any other relevant information about the user.

Adding a User with the adduser Command

Adding a User with the useradd Command

Another tool at your disposal for adding a user is the useradd command. Similar to adduser, useradd also provides an easy and efficient way to add users in Debian. To add a user using useradd, use the following command:

useradd username

This command will add a user to the Debian system without specifying any additional properties. However, you can customize this command to include other properties.

Setting Passwords for the New Users

By default, when adding a user with the useradd command, no password is assigned for login. Therefore, it is necessary to set a password in order to enable interactive login. You can set a password for a new user by executing the following command:

sudo passwd username

Remember to choose a strong password that includes both uppercase and lowercase letters to enhance system security.

Adding Multiple Users with the newusers Command

The newusers command is helpful for adding multiple users at once. With the newusers command, you provide a list of users to be created in a text file. The content of the text file should have the following information:

contents of userlist.txt

You can add multiple users’ information separated by new lines. When your text file is ready, you can use the file to add multiple users to your Debian system with the following command:

newusers < userlist.txt

How to Delete a User in Debian

If a user account is no longer needed, you can delete a user in Debian with the userdel command. To delete a user in Debian, open the terminal and enter the following command:

userdel username

By default, Debian will only delete the user entry, excluding the home directory, mailbox, etc. To completely delete a user in Debian, you need to use the -r flag:

userdel -r username

Conclusion

In this blog post, I have covered different CLI tools for adding users to the Debian system. I have also discussed the method for adding multiple users at a time. Finally, I have covered how you can completely delete a user in Debian.

Share your love

Newsletter Updates

Stay updated with our latest guides and tutorials about Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *