Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to change the default home directory of a user [closed]

Tags:

linux

shell

unix

I would like to know whether there is any simple shell command to change the user home directory in Linux/Unix (one similar to chsh which changes the default login shell of an existing valid user) without touching the /etc/passwd file. Thanks

like image 616
Ibrahim Quraish Avatar asked Dec 27 '13 09:12

Ibrahim Quraish


People also ask

How do I change the default home directory?

You can use the usermod command to change the default home directory for a user. What this command does is edit the file /etc/passwd. Opening /etc/passwd you will find there is a line for every user, including system users (mysql, posftix, etc), with seven fields per line denoted by colons.

How do you change the home directory of the currently logged in user?

You need to edit the /etc/passwd file to change home directory of users that are currently logged in. Edit the /etc/passwd with sudo vipw and change home directory of the user.

What is the default directory for the user's home directory?

By default, it's /home/{username}.


1 Answers

Ibrahim's comment on the other answer is the correct way to alter an existing user's home directory.

Change the user's home directory:

usermod -d /newhome/username username 

usermod is the command to edit an existing user.
-d (abbreviation for --home) will change the user's home directory.

Change the user's home directory + Move the contents of the user's current directory:

usermod -m -d /newhome/username username 

-m (abbreviation for --move-home) will move the content from the user's current directory to the new directory.

like image 111
STW Avatar answered Oct 14 '22 00:10

STW