The useradd is the command line utility in Linux distributions used to add and create new users. When the user is created with the “useradd” command, it will create the home directory for the new user and also copy the initial files related to the user in it.
The useradd is available in almost every Linux distribution with different versions. In Debian, users mostly used the “adduser” command instead of the “useradd” for adding the users. Methods other than the “useradd” to add the users in Debian 12 have been explained in the following post.
This blog will help the users to understand the basic usage syntax of “useradd” command with the help of examples. The outline for this post will be the following:
- What is the Basic Usage Syntax of useradd Command on Debian Linux
- Example 1: Create a User and Set the Password
- Example 2: Create a User with the Specified Directory
- Example 3: Create a User with the Specified UID
- Example 4: Add the User to Multiple Groups
- Example 5: Create a User with the Expiry date
- Example 6: Create a User with the Comments
- Example 7: Display the “help” of useradd
What is the Basic Usage Syntax of useradd Command on Debian Linux?
To add the user with the “useradd” command, run the command following the below-mentioned general syntax:
$ useradd [options] LOGIN
The explanation of the above-mentioned general syntax of useradd command is:
- Use the “useradd” to invoke the command
- Different options of the “useradd” command can be used but it is optional
- Lastly, specify the “username” which is supposed to be created
The next explained examples of using the “useradd” command will give a better understanding.
Example 1: Create a User and Set the Password
Following the basic usage of the “useradd”, create a “sohpia” user by running the command:
$ sudo useradd sohpia
To secure the newly created user, set the password with the command:
$ sudo passwd sohpia
Example 2: Create a User with the Specified Directory
The useradd command creates the user by default in the home directory. To create the user at some other directory, use the “d” option of the “useradd” command as shown:
$ sudo useradd -d /Documents/MyUsers/ milton
Set the password of the “milton” user with the command:
$ sudo passwd milton
To confirm the new specified location of the “milton” user, run the command:
$ cat /etc/passwd | grep milton
Example 3: Create a User with the Specified UID
The User ID is assigned to every user and by default it can be 501, 502, and so on. To create the unique ID of the user, run the useradd command with its “u” option:
$ sudo useradd -u 1009 tim
To display the UID of the user tim, execute the command:
$ cat /etc/passwd | grep tim
Example 4: Add the User to Multiple Groups
To add the user with multiple groups by using a single command, run the useradd command with its “G” option:
$ sudo useradd -G maddox,milton ItsLinuxFoss
Example 5: Create a User with the Expiry date
To create a user for a limited time, define the deletion date of the user account automatically by executing the command:
$ sudo useradd -e 2024-08-27 joe
Also, if it is supposed to expire the password of the above user, run the command:
$ sudo useradd -e 2024-08-27 -f 45 maria
Display the user account information by running the command:
|$ sudo chage -l maria
Example 6: Create a User with the Comments
To create the user with some comments, use the “c” option of the useradd command:
$ sudo useradd -c "Author" Paul
Example 7: Display the “help” of useradd
To explore more information about the useradd command, open its help menu by running the command:
$ sudo useradd --help
This is all about the usage of the useradd command on Debian Linux.
The useradd command line tool is used to add and update the information of the users in Debian Linux. This command can be run with its various options. To use the “useradd” command on Debian 12, follow the general usage syntax explained in this blog.
Some other examples are also used to demonstrate the usage of the useradd command for multiple purposes.