Wednesday, April 25, 2007

How to change your home directory in linux/unix

How do you modify a user's home directory in Unix/Linux?

1. Login as a user with sudo privileges.
2. Enter this command:

sudo nano /etc/passwd
3. Nano text editor opens up. Locate the username you would like to change the home directory of (the last added user is in the end), and just enter whatever directory you would like. For example, the home directory for the user jack is set to /home/jack in this file:

jack:x:1000:1000:Jack,,,:/home/jack:/bin/bash

But I want him to use a home directory of /home/whatever. So I just change the above line to:

jack:x:1000:1000:Jack,,,:/home/whatever:/bin/bash

Now when the user jack logs in, his home directory would be /home/whatever.

Related post for changing home directory in Mac OS X can be found here.

6 people spoke on this:

mustard said...

It is much easier to do the following in "vi". try this..

In the command shell type:
# vi passwd

then edit the specific user.

Anonymous said...

thanks! your post helped me

Jim Warner said...

I think I would leave /etc/passwd alone and use the command
#usermod -d /path/homedir
or if you want to move the stuff from the old /home/user then
#usermod -dm /path/homedir

It's in the man page for usermod.

Jim Warner said...

oops left out something
it should be
#usermod -d /path/homedir login

Works in Red Hat and Fedora. Probably other flavors too.

Leo Batero said...

Guys, you've forgoten the flag "m" is to move the files and content from the old home directory to the new. So the correct scripts is:

sudo usermod -md /my/new/home userid;

Note: don't use "sudo" if you are logged as root.

best regards

Leo Batero said...
This post has been removed by the author.