How to change the home directory of a user account in Linux?

Published August 2, 2021

To change the home directory of a user account, we can use the usermod command followed by the -d flag (home directory flag), then the path to the new home directory, and then the name of the user in the Linux.

Suppose we have a user or an account called john and we would like to change the home directory of the user to the following path: /newhomedir/john.

To do that we can use the usermod command like this,

# Change home directory of a user
sudo usermod -d /newhomedir/john john
  • Sometimes you may need to use the sudo command before the usermod command to obtain the correct privileges to execute the command.

You can also move the contents of the current home directory of the user to the new home directory by using the -m flag (move contents flag). It can be done like this,

# Change home directory of a user
# Also, move the contents of the current
# home directory to the new directory
sudo usermod -d /newhomedir/john -m john

Try executing the above command in this online terminal to see the result.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter