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

The useradd command lets a superuser create a new user account in Linux.

It is a low level utility that doesn’t do a lot of things by default but provides several options to create users with various configuration.

Here’s the syntax of useradd command:

useradd [options] username

Let’s see how to use useradd command.

Useradd command examples

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

Keep in mind that you need to be root or a sudo user in order to use this command.

Add a new user in Linux with useradd command

You can use the useradd command without any options like this:

useradd new_username

It will create the user account but:

  • the user’s home directory won’t be created
  • the password has to be set separately
  • the default shell for the user will be sh

You can set a password for this new user account using the passwd command:

passwd new_username

You can also create home directory while creating the user.

Add a user with home directory with useradd command

The -m option of useradd command allows to copy all files from your system skeleton directory (/etc/skel) to the newly created home directory.

In other words, you can create a user with home directory using the -m option as well.

useradd -m new_username

You can also specify an existing directory as the home directory of the newly created user with option -d.

useradd -d Path_to_Existing_Directory new_username

Add a new user with different shell

The default shell for a user created with useradd command is sh. These days sh shell is hardly used when there is bash and zsh.

A user can change his/er default shell but you can also create the user with a different default shell with the option -s.

For example, if you want the new user to use bash as the default shell, here’s what you can do:

useradd -s /bin/bash new_username

Add a new user with different group

Usually, when you create a new user, a group with the same name as the user is created. The new user is added as the member of this group.

With the option -g, you can add a new user to an already existing group as its default group.

useradd -g Existing_Group_Name_or_ID new_username

Suppose you are creating an account for a developer. Adding all the developers to a ‘dev group’ could be a strategy.

You can also add the user to additional (existing) groups with option -G.

useradd -G group_1 group_2 new_username

So if you are creating a sudo user, you can simply add the user to the sudo group while creating it.

Add a new user with specific user ID (UID)

You may also create a new user with a specific user ID with the option -u of useradd command:

useradd -u uid new_username

Please read this article to know more about UID in Linux.

Bonus Tip: Combine multiple options to create a new user with different parameters

You can combine multiple options together to create a new user in Linux with a predefined configuration.

useradd -d /home/abhishek -s /bin/bash -g my_group 

As you can see, the useradd command by default doesn’t add much. This is why some people prefer to use the adduser command. You can read about difference between useradd and adduser, if interested.

I hope you found the useradd command examples useful. You may also want to learn to delete users with userdel command. Questions and suggestions are welcome.

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

Creator of Linux Handbook and It's FOSS. An ardent Linux user & open source promoter. Huge fan of classic detective mysteries from Agatha Christie and Sherlock Holmes to Columbo & Ellery Queen.

Name

useradd [options] username — shadow-utils

Synopsis

/usr/sbin stdin stdout - file -- opt --help --version

The useradd command lets the superuser create a new user account.

# useradd smith

Its defaults are not very useful (run useradd -D to see them), so be sure to supply all desired options. For example:

# useradd -d /home/smith -s /bin/bash -g users smith

Useful options

-d dir

Set the user’s home directory to be dir.

-s shell

Set the user’s login shell to be shell.

-u uid

Set the user’s ID to be uid. Unless you know what you’re doing, omit this option and accept the default.

-g group

Set the user’s initial (default) group to group, which can either be a numeric group ID or a group name, and which must already exist.

-G group1,group2,…

Make the user a member of the additional, existing groups group1, group2, and so on.

-m

Copy all files from your system skeleton directory, /etc/skel, into the newly created home directory. The skeleton directory traditionally contains minimal (skeletal) versions of initialization files, like ~/.bash_profile, to get new users started If you prefer to copy from a different directory, add the -k option (-k your_preferred_directory).

What does the useradd command do?

useradd is a Linux command for creating a new user. It requires various options to add and set up an active user account. Additionally, the command allows changing default values for the user creation process. useradd is a low-level, portable command available on all Linux distributions.

What command do you use to add a user with the default home directory?

By default 'useradd' command creates a user's home directory under /home directory with a username.

Which useradd command line switch create user home directory?

useradd is a command in Linux that is used to add user accounts to your system..
/etc/passwd..
/etc/shadow..
/etc/group..
/etc/gshadow..
creates a directory for new user in /home..

When using useradd to create a new user account which of the following tasks is not done automatically?

Which of the following tasks is not performed automatically for a user account when it is created using the useradd command? The useradd command does not create the user's home directory by default.