How To Add User in Debian 12

If you have multiple people who need to use the same Debian system, creating separate user accounts is essential. It improves the system security and allows the super user to add permissions for users. More importantly, each user can fully customize their desktop settings, applications, and files in their home directory thus avoiding conflicts with other users. So if you are looking to add a user in Debian 12, this guide will discuss all the possible ways for it.

3-Ways to Add User in Debian 12

To add a user in Debian you need to have a super user account or in other words, the account should be in the sudoers file. To add users to sudoers read my detailed guide on How To Add Users in Sudoers File in Debian 12. If you try to add a user either via adduser or useradd command without sudo privileges or without logging in to the root account you will get the command not found error as in the image below:

adduser command not found and useradd command not found error in Debian

Now as in the image below just for clarification I have used the adduser command with sudo privileges and see there is no error:

Executing adduser command with sudo on Debian 12

Furthermore, I have also demonstrated that you can also add a user by logging into the root account as in the image below:

Executing adduser command in root account in Debian

Further, before jumping to adding a user in Debian you should know what type of details a user has in Debian and other Linux operating systems. In the below image, I have read the data of user Sarah in passwd file:

Reading passwd file for specific user in Debian using cat /etc/passwd | grep [user-name} command

Now to understand these details see the image below:

Detailed illustration of cat /etc/passwd [user-name] command. In short it is the explanation of user details of passwd file in Debian.

1: Through useradd Command

The first method to add a user in Debian 12 is by using the useradd command however there are multiple options that you can use to add the user. The simple way is to add a user using the useradd command syntax given below:

useradd -m [name-of-new-user]

Now here I have used the m flag which will create a home directory for the created user. If no flag is used with useradd command then the user will be created based on the default settings.

Creating a user with home directory in Debian using useradd command.

Once the user is created next set the password for the user by using the passwd command:

sudo passwd [name-of-new-user]

Setting the password for the newly created user in Debian 12

After you have created a user in Debian you can verify its details by reading the passwd file via executing the following command:

cat /etc/passwd

verifying the user creation by reading passwd file in Debian using cat command

Further, you can create a user along with setting its password by using the p flag for the password as in the syntax below:

sudo useradd -m <name-of-new-user> -p <password-for-new-user>

Creating a user along with its home directory and password in Debian using the useradd command

To segregate the users in the Linux operating system you can create groups and allow permissions based on their role. So if you want to create a user and add it to sudo groups then use the below syntax:

sudo useradd -m -G sudo [Name-of-new-user]

creating a new user and adding it to sudo group in Debian using useradd command

Further to verify the allocation of groups to the user simply use the getnet command as given below:

grep '^sudo:' /etc/group

Verifying the user in a group using grep command in Debian 12

Adding Users with Different Home Directories

As mentioned earlier, with useradd command you can use loads of different options so if you want to create a user with a different home directory then first you need to create a new directory. Next, you can use the below command syntax for adding a user with a different home directory.

sudo useradd -d /[different-home-directoy-path] [new-user-name]

This way each user can have their own space to avoid mixing up their data with other users in Debian 12:

Adding user in Debian to a separate home directory and setting its password using useradd and passwd command.

Now there are two ways to verify the home directory of a user in Debian, you can use any of the two commands given below:

echo ~ [user-name]

cat /etc/passwd | grep [User-name]

Here, you can see the Sarah user has been added to the communications directory:

Verifying user directory by two ways that is by executing echo`[user-name] and cat /etc/passwd | grep [user-name] command in Debian.

Adding a User with a Custom User ID

On Debian and other Linux distributions, each user has a unique ID issued randomly for every user. So you can also create a user in Debian 12 with the desired ID and for that use the below syntax:

sudo useradd -u [desired-user-ID] [user-name]

Adding a user in Debian 12 with custom user ID and then verifying it by using the cat /etc/passwd | grep [user-name] command.

Adding a User with an Expiry Date

If you are allowing a user to access Debian for only a limited time then you can add an expiration date to the user details. This will prompt the deletion/inaccessibility of the account on the specified date:

useradd -e [YYY-MM-DD] [user-name]

Adding a user in Debian 12 with expiration date using useradd command. Also verifying account expiry date using sudo chage -l [user-name] command.

Further, if you want to explore more options for using adduser command then use the help flag as in the command below:

sudo adduser --help

Executing help command for adduser for getting any additional information on Debian

2: Through adduser Command

Another way to add a user in Debian is to use the adduser command by following the given syntax below:

sudo adduser [user-name]

The adduser asks about the user account password and some other information about the user. Whereas in the useradd command, you have separately add the information.

Adding a user in Debian using the adduser command.

The options for the adduser are pretty much similar to that of useradd command and to explore its options execute:

sudo adduser --help

Executing help command for useradd for getting any additional information on Debian 12

3: Through the System User Settings

On Debian, if you want to add a user with no additional settings or permissions then use the Debian 12 system settings menu. To add a user first you need to unlock the user settings:

Accessing user settings in Debian

Next, click on the Add User option:

Adding a user in Debian 12 through its system settings

Now add the details of the user which includes its name, password, and basic permission setting. Afterward, click on the Add option:

Adding a user in Debian through its user settings in system settings. Adding user name, password and admin permission.

Now here you can see that a user has been created:

Added a user in Debian via its user settings in system settings.

On the other hand, if your system is connected to the company server then you can also create an Enterprise Login:

Creating an Enterprise Login in Debian for adding a user.

Here add the Domain matching the web address of the login provider and then set the username and password, afterward click on the Add option:

Creating an Enterprise Login by adding domain, username and password in Debian 12

How to Add a User to a Group in Debian 12

To have simplified permission management and to define different access levels, groups are used. So on Debian 12, you can add a user in a group instead of setting permissions for each user individually. Below is a syntax for adding a user in the sudo group:

sudo usermod -aG sudo [Name-of-user]

Adding user to a sudo group in Debian using usermod command

Adding a User with a Custom Group ID

Further, you can also add a user to a group using its group ID. Here I have first listed all the groups along with their IDs using the following command:

getent group

Listing all the groups on Debian 12 using getent group command

Here is the syntax for adding a user to a group in Debian using the group ID:

sudo useradd -g [group-ID] [user-name]

For instance, I want to add a user to the management group so I have used the management group ID along with the user name. Next, I have verified the user group as well by reading the passwd file of Debian:

Adding user with custom group ID in Debian using the useradd command. Also verifying the group ID using the cat /etc/passwd | grep [user-name] command.

Further, you can also verify it with the group command:

groups [user-name]

Verifying the user group by executing groups [user-name] command

How to Modify the User Details in Debian 12

In Debian and other Linux systems sometimes it is necessary to add the details of a user which can help in identifying their role and responsibilities. Furthermore, if you use the useradd command for adding a user in Debian then you have to manually add the details of the user. For that use the usermod command, so here are some things that you can modify or add to user details in Debian.

How to Change the Shell Type of a User in Debian 12

Shell in Debian and other Linux distributions acts as an interface between the user and the operating system. So if you want to change the shell type of a user in Debian then use the below command syntax:

sudo usermod -s <shell-name> <user-name>

Here, as you can see in the image below I am setting zshell as the shell type of user Sarah in Debian but I am getting the error of missing or non-executable shell. This is because on my Debian system, zshell is not installed:

usermod: Warning: missing or non-executable shell '/bin/zsh/' error while changing the shell type of a user in Debian 12

So I have installed it first using the apt package manager:

sudo apt install zsh

Installing Z shell on Debian 12 to fix usermod: Warning: missing or non-executable shell '/bin/zsh/' error.

Next, I used the usermod along with the s flag for shell type. Further to verify the shell type setting you can read the passwd file using grep and cat command:

Changing a shell type of a user in Debian by executing sudo usermod -s /bin/zsh [user-name]

How to Change the User ID of a User in Debian 12

The user ID is an identification number that is used in Debian and other Linux operating systems which can be changed based on the preference of the user. This is helpful if you want a certain number of users with the same series of user IDs which will segregate users. To set a custom or any specific user ID in Debian use the following syntax below:

sudo usermod -u [desired-user-id][user-name]

Setting a custom user ID for a user in Debian and verifying it by executing cat /etc/passwd | grep [user-name]

How to Add any User Information in Debian 12

Adding any information about the user as previously mentioned can help in identifying the role and responsibilities. In that case, use the below syntax for adding any info for the user in Debian:

sudo usermod -c "[user-information-to-be added]" [user-name]

Adding an information for a user in Debian and verifying it by executing cat /etc/passwd | grep [user-name]

Conclusion

To add a user in Debian there are primarily three ways which include using useradd command, adduser command, and the system settings method. Further, you can use several different options along with useradd and adduser commands to add any details of the user. The recommended way to add a user if you need to add several user details is by using the useradd command otherwise the best way is using Debian system settings.

 

Index
Scroll to Top