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:


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


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.


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...
This comment has been removed by the author.
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

Anonymous said...

Its a very good question.It help to us.
For Change Working Directory.

cd / go to the root directory
cd go to your login (home) directory
cd ~username go to username's login (home) directory
not allowed in the Bourne shell
cd ~username/directory go to username's indicated directory
cd .. go up one directory level from here
cd ../.. go up two directory levels from here
cd /full/path/name/from/root change directory to absolute path named
note the leading slash
cd path/from/current/directory change directory to path relative to here.
note there is no leading slash
You should check this link and you get more information

Satyanarayanan said...

Thanks...Your post helped me to do what i wanted badly

tonytopper said...

usermod won't let me change my home directory because it keeps saying I am logged in.

JamesR404 said...

@topytopper Just log in with another user and then run the command.

You can use this command to see what users are defined on the system:
awk -F: '{ print $1 }' /etc/passwd

If you don't have another account you may need to create one before you can change the home directory?

Someone cmiiw

James Baber said...

Thank you very much, your article was very usefull!

eddy shaw said...

There may be noticeably a bundle to find out about this. I assume you made certain nice factors in features also. bovada casino