How to change home directory of a linux user

You can modify a user’s home directory using usermod command in Linux.

The syntax for the usermod command is

sudo usermod -d PATH_TO_HOME_DIR USER_NAME

Example

I have a user “sok_user1” with home directory /home/sok_user1

root@ok:~# cat /etc/passwd | grep sok_user1
sok_user1:x:1004:1005::/home/sok_user1:/bin/bash
root@ok:~#

To change the users home directory to /var/www/, we can use the command

usermod -d /var/www sok_user1

Example

root@ok:~# usermod -d /var/www sok_user1
root@ok:~# cat /etc/passwd | grep sok_user1
sok_user1:x:1004:1005::/var/www:/bin/bash
root@ok:~# 

Back to Linux User

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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