How to Create a User in Linux (With Home Directory)

The quickest way: useradd -m
Most efficient way would be the usage of the useradd command with the -m option.
Invoke sudo useradd -m username in order to add new user and his home directory in one go. The flag -m tells useradd to create a home directory in default place /home/username and copy all standard files from /etc/skel into it.
For example:
sudo useradd -m aliceHere we've created the account, created /home/alice and copied all files from /etc/skel into it as the basic set of files for the new user.
Verification of the creation of a home directory
Check for the presence of the directory and ownership:
ls -la /home/alice
id alice
getent passwd aliceThe first command confirms the folder is there and prints its owner and permissions. Next, id confirms the user exists, along with its user ID and group ID. Finally, getent passwd prints the user's complete password-file entry, home directory path included, which is handy for confirming that a custom home path was applied.
Setting password for a new user
The useradd command creates the account in the locked state, without a password configured. You can assign the password using the command:
sudo passwd aliceYou'll be asked for the password and confirmation of it. Until this step will be done (or the alternate ssh key authentication will be configured) this account can not be used for logins.
The reason for a lack of a home directory while using useradd
Now let's clarify why in some cases the account created by simple invocation useradd alice doesn't have home directory.
The useradd manual explains that -m is what creates the home directory; leave it out, and a home directory appears only when CREATE_HOME is turned on in /etc/login.defs. On Red Hat-type distributions that setting is usually yes, so a home directory gets created with or without -m. Debian and Ubuntu leave it unset, so leaving out -m means no home directory. Scripts meant for more than one distribution should always include -m.
Alternative useradd: adduser
Debian and Ubuntu also ship adduser, and it is more than a friendlier alias. useradd is the low-level binary every Linux distribution includes. On Debian-based systems, adduser is an extra script on top of it: it calls useradd under the hood, prompts for a password and other details, and creates the home directory by default, with no -m needed.
For example:
sudo adduser aliceBut there is a twist: adduser doesn't work the same way everywhere. On Fedora and RHEL it is simply a link to useradd and behaves just like it, usually without prompts. So for a script that targets several distributions, useradd -m is the safer choice, because it behaves the same on all of them.
Customizing the account
There're some options that will cover common customization of an account:
Option | Description |
|---|---|
| Creates the home directory if it does not already exist |
| Use the given home directory (rather than default |
| Use the specified skeleton directory (rather than default |
| Use the given shell (for example, |
| Add user to the additional groups |
| Set the GECOS field (full name of the user) |
For example:
sudo useradd -m -d /srv/users/alice -s /bin/bash -G sudo,docker -c "Alice Chen" aliceHere the account is created with custom home directory location outside the default /home hierarchy, /bin/bash is set as login shell, user is put into sudo and docker groups and his full name is specified in GECOS field.
Fixing the existing account without a home directory
If there's already an account created without -m and you found out that it is missing the home directory, there's no need to delete and recreate it. You can create it and direct the account to this directory:
sudo usermod -d /home/alice -m aliceGiven -m, usermod shifts the old home directory's files to the new location. When no old home directory exists, a fresh /home/alice gets created. In both cases, unlike useradd -m, usermod won't copy skeleton files or set ownership, so handle those steps manually:
sudo cp -rT /etc/skel /home/alice
sudo chown -R alice:alice /home/aliceThese steps are typical for the initial server configuration. OrbitServers VPS and bare-metal instances typically come with full root access right after boot, allowing useradd -m to work as intended without any additional configuration.
Get started with Orbit Servers
Low-latency VPS, bare metal, and colocation across the US, EU, and APAC - provisioned instantly and built for performance-critical workloads.
Get startedRelated products
Written by
Julius
Product Manager
Julius is a product-minded builder who cares about making technology simpler and more useful for the people who rely on it. He’s always looking for ways to improve things, one small step at a time, and enjoys turning good ideas into products that work.