The useradd
command in Unix-like operating systems is used to create new user accounts. It allows system administrators to manage user database entries efficiently. One of the options available with the useradd
command is -l
(or --no-log-init
), which is particularly useful for managing user entries without initializing the user’s login session. Let’s explore how this option works with some examples:
Example 1: Create a new user without initializing the login session:
$ sudo useradd -l newuser
This command adds a new user named “newuser” to the system but does not initialize their login session. To verify, you can check the existence of the user in the system’s user database using commands like id newuser
or getent passwd newuser
.
Example 2: Add a new user with custom options and without login initialization:
$ sudo useradd -l -m -s /bin/bash newuser2
Here, the -m
option creates the user’s home directory and -s /bin/bash
sets the user’s default shell. The -l
option ensures that the login session is not initialized upon creation.
Example 3: Create a system account without a login session:
$ sudo useradd -l -r systemuser
This command adds a system user named “systemuser” with the -r
option, which is typically used for creating accounts used by services and daemons. The -l
option ensures no login session is initialized.
Example 4: Create a new user with a specific UID and without login initialization:
$ sudo useradd -l -u 2001 customuser
Here, -u 2001
specifies the UID (User ID) for the user “customuser”. The -l
option ensures that no login session is initialized upon creation.
Each of these examples demonstrates how the -l
option of the useradd
command can be used to manage user database entries without initializing the user’s login session. To verify whether the commands executed successfully, you can use tools such as id
, getent
, or examine system logs to ensure the user account was created as intended.
Discussion about this post