The useradd
command in Unix-like operating systems is used to create new user accounts. One of its options, -M
or --no-create-home
, prevents the creation of a home directory for the newly added user.
This option is particularly useful in scenarios where you want to add a user account without allocating a home directory. Let’s explore a few examples to understand its usage:
Example 1: Adding a user without creating a home directory.
useradd -M john_doe
This command adds a new user john_doe
without creating a home directory.
Example 2: Adding a user with specific options.
useradd -M -s /bin/bash -c "John Doe" johnd
This command adds a user johnd
with the specified shell (/bin/bash
) and a comment (John Doe
), without creating a home directory.
Example 3: Adding a system user.
useradd -M -r system_user
This command adds a system user system_user
without creating a home directory.
To verify if the -M
option worked as expected, you can check the presence of the home directory. After executing the command, if no home directory is created for the user, it indicates that the option was applied successfully.
Discussion about this post