How to Move a User’s Home Directory on Linux

A home directory is a user’s default directory when they log into Linux. It’s normally created automatically inside of the /home directory, such as /home/username. In this tutorial, you will learn how to change the home directory for a user in Linux by using the usermod command.

Step 1. First, let’s create a new directory that we would like to use for the user’s home directory.

$ mkdir /home/linuxnightly

Step 2. You can alter a home directory with the usermod command and the -d flag. This command must be executed with root permissions. Also keep in mind that the user must be logged out when you are attempting to change their home directory.

$ sudo usermod -d /home/linuxnightly username

Substitute your own directory in the above command, and replace “username” with the actual name of your user.

Step 3. You can confirm that the change worked by logging into the user whose home directory you just modified.

$ su username

Step 4. Then, execute the pwd command to see the current directory. If the change worked, you’ll see the directory you configured.

$ pwd

Leave a Comment

Your email address will not be published. Required fields are marked *