What option to the useradd command causes the users home directory to be created during the user creation process?

The useradd program has been deprecated in favor of adduser. From man useradd:

useradd is a low level utility for adding users. On Debian,
administrators should usually use adduser(8) instead
.

adduser is a friendlier frontend to useradd and will do things like create user directories by default. When you run it with only a username as an argument, you will be prompted to provide additional information such as the password:

$ sudo adduser testuser Adding user `testuser' ... Adding new group `testuser' (1002) ... Adding new user `testuser' (1002) with group `testuser' ... Creating home directory `/home/testuser' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for testuser Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]

In general, you should always use adduser instead of useradd since this will also set up the required groups automatically. As explained in man adduser:

adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd, groupadd and usermod programs, by default choosing Debian policy conformant UID and GID values, creating a home directory with skeletal configuration, running a custom script, and other fea‐ tures.

Linux is a powerful multi-user operating system. It can have many concurrent users accessing the system at the same time. The system admin can manage permissions for each user to specify which user can access what part of the system.

This guide will demonstrate how to create a new user with a different home directory in Linux.

In Linux, each user gets its own home directory with exceptions like various system accounts. The home directory is a dedicated directory for the particular user to store the user-specific files. It’s also referred to as the “login directory”. Whenever logging in, the user will land on the respective home directory.

By default, all the users in the system have their home directories located at the following location.

What option to the useradd command causes the users home directory to be created during the user creation process?

Each home directory is named after the username of the user. For example, the home directory for the user “viktor” will look like this.

What option to the useradd command causes the users home directory to be created during the user creation process?

However, we can establish a different location for the user directory. It can be set during the creation of the user account or moved later.

Creating a user with a different home directory

Creating a new user

Each Linux system comes with useradd, a dedicated tool to create and update user accounts. It’s only available to the root user and non-root users with sudo privileges.

To add a new user to the system, run the following useradd command. The flag “-m” tells useradd to create a dedicated home directory for the new user. If not used, then the user won’t have a dedicated home directory.

$ sudo useradd -m <username>

What option to the useradd command causes the users home directory to be created during the user creation process?

The user is added to the system. The user is also registered to various database files (/etc/passwd, /etc/shadow, /etc/gshadow, and /etc/group).

The user isn’t accessible yet. The following command will assign a login password for the new user.

What option to the useradd command causes the users home directory to be created during the user creation process?

The user is ready and fully functional. Access the new user.

Check the location of the home directory of the new user.

What option to the useradd command causes the users home directory to be created during the user creation process?

Creating a user with a custom home directory

By default, useradd will create the user’s home directory under “/home”. To specify the home directory in a different location, use the flag “-d”. Note that the directory must exist beforehand.

$ sudo useradd -m -d <custom_home_dir_location> <username>

What option to the useradd command causes the users home directory to be created during the user creation process?

As always, use passwd to assign a login password for the new user.

What option to the useradd command causes the users home directory to be created during the user creation process?

Verify if the new user has a different home directory.

What option to the useradd command causes the users home directory to be created during the user creation process?

Moving existing user home directory

We can also assign a different home directory for an existing user. It will not move the contents of the existing home directory automatically to the new location.

Create a new directory. It will be the new home directory of an existing user.

$ mkdir -pv /extra/new_home

What option to the useradd command causes the users home directory to be created during the user creation process?

Allow the new user complete access over the new directory.

$ sudo chown <username> /extra/new_home

What option to the useradd command causes the users home directory to be created during the user creation process?

Move all the contents of the existing user home directory to the new one.

$ sudo mv /home/<username>/* /extra/new_home

Assign the new directory as the home of the user.

$ sudo usermod -d /extra/new_home -m <username>

What option to the useradd command causes the users home directory to be created during the user creation process?

Verify the change.

What option to the useradd command causes the users home directory to be created during the user creation process?

Final thoughts

The home directory is an important part of a normal user account on Linux. This guide demonstrates how to assign a custom home directory to a new and existing user. These methods apply to any Linux distro.

Happy computing!

About the author

What option to the useradd command causes the users home directory to be created during the user creation process?

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.

What option to the useradd command causes the user's home directory to be created during the user creation process?

useradd Command Options.

Does the useradd command create a home directory for the user by default if so where?

Note that useradd will not create a home directory for such an user, regardless of the default setting in /etc/login. defs (CREATE_HOME). You have to specify the -m options if you want a home directory for a system account to be created.

Which option can be used with useradd to create a new user without a home directory?

Here we used the '-M' option to create a user without the user's home directory and the '-N' argument is used that tells the system to only create a username (without group).

Which option needs to be set to create a home directory?

If you want the useradd command to create a new home directory for your user, you will need to append the -m option. To configure a custom home directory for the new user, you will need to use the -m option like in the previous example, but also add the -d option and specify the new path to the home directory.