Home Linux Commandline Tips How to Change Default User Home Directory in Linux

How to Change Default User Home Directory in Linux

Before we can jump into changing the default user home directory on a Linux operating system environment, we should brief through some theoretical and practical information related to the Linux home directory.

By definition, Linux is a multi-user operating system, which creates the need for a universal directory called the Home directory where different OS users can store and create personalized/user-centered files and directories.

These files and directories are only accessible to the homeowner (currently logged-in user). Therefore, each time a new user is created on a Linux environment, the user is associated with a unique home directory accessible only to that user.

On the other hand, the existence of these universal directories also permits a universal user (other than the homeowner) to have access to them. This user is known as root and can access all homeowner directories within a Linux system.

The syntax associated with a user’s Home directory is as follows:

/home/directory_name

For instance, if a Linux system has a user called dnyce, then the absolute path to this user’s Home directory will be:

/home/dnyce  

We can even list the permission settings associated with the user in the following manner:

$ ls -ld /home/dnyce
List User Home Directory
List User Home Directory

This article will walk us through changing the default user home directory on a Linux operating system environment.

Benefits of Having a Linux Home Directory

We can summarize the benefits of having a Linux Home directory in the following manner.

  • User Access Restriction – It is only the homeowner and root user that can access this directory making it impossible for other users to tamper with existing customization settings and stored configuration files. Therefore, privacy and security are guaranteed.
  • Controlled Environment – Since multiple homeowners can exist within a single Linux system, their restriction on their Home directories is very advantageous. For instance, if a homeowner’s Home directory contains malicious code in stored executable files, the execution of this code will only affect that user environment and not the entire system.
  • Controlled Flexibility – The user’s Home directory is automatically created during the Linux installation. During this installation process, a user can decide to assign this directory an exclusive partition. This step makes it easier to execute backup and restoration tasks.

Changing Default User Home Directory in Linux

We will need to create a sample Linux user account for this tutorial to be more practical. Since creating a new user in Linux is associated with a Home directory, let us create one.

# useradd -m homeowner 
# passwd homeowner

The -m flag makes sure that a default user Home directory is created and set a password to the user.

Create New User in Linux
Create New User in Linux

We can now switch to the newly created user account and confirm the default user home directory.

# su - homeowner
$ pwd
Check User Home Directory
Check User Home Directory

Switch back to the root user account.

$ exit

and create a new directory replacement for the default user Home directory.

# mkdir /home/newowner 

We will assign user homeowner directory ownership for the newowner.

# chown -R homeowner:homeowner /home/newowner

Now, to change the user’s default Home directory from /home/homeowner to the new directory /home/newowner, we will make use of the usermod -d command in the following manner.

# usermod -d /home/newowner homeowner 

The -d flag sets the directory.

Change Linux User Home Directory
Change Linux User Home Directory

We can switch back to the homeowner account and confirm the changes.

# su - homeowner
$ pwd
Confirm User Home Directory
Confirm User Home Directory

Alternatively, we could set the preferred user Home directory during user creation in the following manner.

# useradd -m -d /home/newowner homeowner 

The -d flag sets the directory.

While changing the default user Home directory, we might also need to migrate/move already existing user content to the new location. The usermod command to implement is:

# usermod -m -d /home/newowner homeowner

The -m flag moves the old directory content to the new one.

We can now easily change the default Home directory in Linux. I hope this article guide was helpful. Feel free to leave a comment or feedback.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.