Centos – How to change the Home directory of the currently logged In user

centoshomelinuxusers

I am currently logged in into a CentOS server and I would like to change my home directory from /home/myuserName/ to /var/www/html/

I tried the below command :

> sudo usermod -d /var/www/html myuserName

But this gives me an error:

usermod: user myUserName is currently logged in

Best Answer

short answer : you can't.

long answer:

HOME dir is set in /etc/passwd, 6th field. It is read upon login; your shell is started with this home dir.

The proper way to change home dir for joe is :

  • have joe log off.
  • use usermod -d /new/home joe to change home dir for subsequent session.

Once session is run, you must do two things:

  • edit $HOME to change home dir for session (to be repeated on all active session).
  • use sudo vipw to edit home dir for next session

Also, be aware you might have an issue with permissions/ownership on /var/www/html.