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:
Now as in the image below just for clarification I have used the adduser command with sudo privileges and see there is no error:
Furthermore, I have also demonstrated that you can also add a user by logging into the root account as in the image below:
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:
Now to understand these details see the image below:
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.
Once the user is created next set the password for the user by using the passwd command:
sudo passwd [name-of-new-user]
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
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>
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]
Further to verify the allocation of groups to the user simply use the getnet command as given below:
grep '^sudo:' /etc/group
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:
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:
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 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]
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
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.
The options for the adduser are pretty much similar to that of useradd command and to explore its options execute:
sudo adduser --help
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:
Next, click on the Add User option:
Now add the details of the user which includes its name, password, and basic permission setting. Afterward, click on the Add option:
Now here you can see that a user has been created:
On the other hand, if your system is connected to the company server then you can also create an Enterprise Login:
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:
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 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
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:
Further, you can also verify it with the group command:
groups [user-name]
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:
So I have installed it first using the apt package manager:
sudo apt install zsh
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:
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]
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]
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.