​​How to Add a New User on Debian 12?


Debian 12 allows many users to operate on a device. These users interact with the Operating System without affecting other users. A user is classified into a system and a regular user. When we install a software package, a system user is created with a user ID range of 100-999. System users manipulate software. Alternatively, a regular user account is created with user IDs above 1000. It is for users that share a particular device, such as admin, employees, etc. The system and regular users’ details are contained in the /etc/passwd file.

This article will demonstrate different methods of adding a new user on Debian 12 (Bookworm) systems, with the following outline:

Let’s begin with adding a user via the Command Line Interface (CLI).

How to Add a New User on Debian 12 via CLI?

A new regular and a system user can be added via adduser, useradd, and newusers commands as demonstrated below:

1. adduser Command

This command creates/adds a user with the additional details of the user, i.e., Password, Full Name, Phone Details, etc. The following sections demonstrate various use cases/examples of the adduser command:

Regular User

The following command adds a new user linuxgenie1:

sudo adduser linuxgenie1

The newly created user can be verified by several methods:

User ID

id linuxgenie1

There are two other verification methods (commands) as well:

  • awk -f: ‘$3 >= 1000 {print}’ /etc/passwd: Fetch users with user ID >= 1000 from the /etc/passwd file
  • grep ‘users’ /etc/group: Fetch all users of the ‘users’ group as adduser creates ‘user’ in the “users” group.

System User

The following command adds a system user linuxgenies1:

sudo adduser --system linuxgenies1

To verify, fetch system users with user-id ($3) less than 1000:

awk -F: '$3 < 1000 {print}' /etc/passwd

Scroll down the output and you will get the newly created user, as shown below:

2. useradd Command

The useradd command adds a new user but it doesn’t create the home directory, password, login/default shell, etc. The below sections demonstrate the addition of a regular and system user via the useradd command:

Regular User

The following command adds a new user linuxgenie2:

sudo useradd linuxgenie2

To verify, fetch regular users with user-id ($3) greater than or equal to 1000:

awk -F: '$3 >= 1000 {print}' /etc/passwd

How to Create and Add a User in a Specific Group?

The following command creates a user linuxgenie2 and adds it to the “users” group:

sudo useradd linuxgenie2 -G users

To verify, search all users in the “users” group by the following command:

grep 'users' /etc/group

How to Set a Password for a Regular User?

Contrary to the adduser command, the useradd command creates a user without a password. To set a password, execute the following command and set the password at the prompt:

sudo passwd linuxgenie2

System User

To add system user linuxgenies2, run the command below:

sudo useradd --system linuxgenies2

To verify, fetch system users with user-id ($3) less than 1000:

awk -F: '$3 < 1000 {print}' /etc/passwd

What is the Difference Between the User added Through the adduser and the useradd Commands?

The adduser and useradd commands are available on Debian12 by default and both commands add/create a user. The main differences between these commands are listed below:

  • The adduser command creates a user via an interactive prompt as compared to the useradd command.
  • The adduser command considers parameters, such as password, home directory, user ID, default shell, etc. Alternatively, the useradd command only creates a user. However, the user parameters can be added via flags.
  • After user creation, the user parameters can be modified via the useradd command, contrary to the adduser command.

3. newusers Command

The newusers command enables users to add multiple regular and system users in bulk by the following steps:

  • Step 1: Create a File.
  • Step 2: Add users separated by a new line in the text file. Each user is added in the format of /etc/passwd file shown below:

user_name:password:user_id:group_id:general_comments:home_directory:default_shell

  • Step 3: Read the text file via the newusers command.

The below sections demonstrate the addition of a regular and system user via the newusers command:

Regular User

Create a txt file users.txt by using the Nano text editor:

nano users.txt

Then, add six users: linuxgenie1,linuxgenie2, linuxgenie3, linuxgenie4, linuxgenie5, and linuxgenie6 users by editing nano.txt file:

linuxgenie1:test1:1001:1001::/home/linuxgenie1:/bin/sh

linuxgenie2:test2:1002:1002::/home/linuxgenie2:/bin/sh

linuxgenie3:test3:1003:1003::/home/linuxgenie3:/bin/sh

linuxgenie4:test4:1004:1004::/home/linuxgenie4:/bin/sh

linuxgenie5:test5:1005:1005::/home/linuxgenie5:/bin/sh

linuxgenie6:test6:1006:1006::/home/linuxgenie6:/bin/sh

Next, add the users placed in the text file (users.txt), as follows:

sudo newusers users.txt

To verify, fetch regular users with user-id ($3) greater than or equal to 1000:

awk -F: '$3 >= 1000 {print}' /etc/passwd

System User

To add multiple system users, i.e., linuxgenieS1, linuxgenieS2, linuxgenieS3, linuxgenieS4, linuxgenieS5, and linuxgenieS6, first create a text file, users.txt:

nano users.txt

Then, edit the file and enter the users:

linuxgenieS1:test1:991:1::/home/linuxgenieS1:/bin/false

linuxgenieS2:test2:992:1::/home/linuxgenieS2:/bin/false

linuxgenieS3:test3:993:1::/home/linuxgenieS3:/bin/false

linuxgenieS4:test4:994:1::/home/linuxgenieS4:/bin/false

linuxgenieS5:test5:995:1::/home/linuxgenieS5:/bin/false

linuxgenieS6:test6:996:1::/home/linuxgenieS6:/bin/false

Save and exit the editor by pressing [Ctrl + O] and [Ctrl + X] respectively.

Next, execute the following command to create system users via the newusers command:

sudo newusers --system users.txt

To verify, fetch system users with user-id ($3) less than 1000:

awk -F: '$3 < 1000 {print}' /etc/passwd

How to Add a New User on Debian 12 via GUI?

To add a new regular user linuxgenie1 with administrative privileges via Graphical User Interface (GUI), open Settings and access the Users section (in the left pane). Then, press the Unlock button to add users and change settings:

The system will prompt for authentication. Enter the password and press the Authenticate button:

Next, press the + under the Other Users section:

  • Enter the complete name in the Name textbox, e.g., linuxgenie1.
  • Next, enter the user name in the username textbox, e.g., linuxgenieUser.
  • Then, allocate the administrator rights to the user by turning on the toggle button.
  • Subsequently, choose the “Set password now” radio button, and create and confirm the password.

Finally, press the Add button:

A new user linuxgenie1 is created:

The user can access the newly created user by switching users:

Note: A system administrator cannot add a system user via GUI.

Bonus Tip 1: How to Assign Sudo Privileges to a Regular User?

To assign sudo privileges to a regular user, add the user to the sudo group by executing the following command:

sudo usermod -aG sudo linuxgenie1

To verify, check the group ID of all the groups linuxgenie1 is added to by

id linuxgenie1

The user, linuxgenie1 is added to the sudo group with the group ID 27.

Bonus Tip 2: How to Delete a User From/in Debian 12?

A user can be deleted via CLI and GUI as demonstrated below:

Using CLI

To delete a regular/system user, execute the following command:

sudo deluser linuxgenie2

Using GUI

A system administrator/user with administrator privileges can delete any user. To delete a user, Navigate to the Users section in the Settings. Then, press the Unlock button to change user settings:

The system will prompt for authentication. Enter the password and press the Authenticate button:

Select the user to be deleted from the “Other Users” section:

Press the “Remove User” button:

There will be a prompt for confirmation to keep/delete files associated with the user account. Press Delete Files:

Conclusion

There are many ways to add a new user on Debian 12. By CLI, a new regular and system user is added by adduser, useradd, and newusers commands. Only one user is added at a time via the adduser and useradd commands. Whereas, the newusers command allows the addition of users in bulk. By GUI, a new user is added via Settings.

GUI enables the creation of a user with administrative privileges. On the other hand, the user added via CLI methods has to be dedicatedly added to the sudo group for administrative privileges. This article presented three (3) different methods of adding a new user via CLI alongside a GUI method.

Print Friendly, PDF & Email