Normal user accounts on Linux have their own home directory. This is the location where all of the user account's personal files typically reside, including their recent downloads, desktop contents, etc.

By default, a user's home directory is usually located at /home/username where "username" is the name of the user account. However, you can actually place a user's home directory just about anywhere you'd like. Linux gives us the option to choose a location for the home directory whenever we are creating a new user.

In this guide, we'll go over the commands needed to specify a custom home directory when creating a new user on Linux.

In this tutorial you will learn:
  • How to create a user with a custom home directory
Adding a new user with custom home directory on Linux
Adding a new user with custom home directory on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

How to create a user with a custom home directory

We can add a user to a Linux system with the useradd command. In order to specify a custom home directory location, we need to use the -d option with the command.

As an example, the following command will create a new user named testuser and set their home directory to /users/testdirectory.

$ sudo useradd testuser -d /users/testdirectory

Keep in mind that this option doesn't automatically create the directory we specify. To create the user directory automatically, we'll have to include the -m option.

$ sudo useradd testuser -m -d /users/testdirectory

SUBSCRIBE NEWSLETTER & RSS
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


Adding a new user with custom home directory on Linux
Adding a new user with custom home directory on Linux

Conclusion

That's all there is to it. The command line method shown here remains the best way to accomplish this task, as default GUI tools usually don't provide us with the ability to specify a custom home directory. In this guide, we've seen how to specify a custom home directory for a new user we create, and optionally create the directory if it doesn't already exist.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.