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
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
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
$ 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
$ sudo useradd testuser -m -d /users/testdirectory
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.