4

I use this command to change my home directory:

sudo usermod -d new-path -m myname

But I got this error:

usermod: user myname is currently logged in

How could I change my own home directory and move all files into new-path? This server is a remote virtual machine, and connected with putty (Ubuntu 12.04).

Jens Erat
  • 5,051
  • 7
  • 31
  • 37
Bangyou
  • 201
  • 1
  • 3
  • 8
  • 6
    You may able to do it as root from a TTY - see this question – Wilf Aug 16 '14 at 11:07
  • 1
    log out. do control-alt-f1. log in. change it. type "exit". control-alt-f7. log in again. – Rinzwind Aug 16 '14 at 11:10
  • 1
    Thanks for your suggestion. Sorry I forgot to mention this server is a remote VM and I connect with putty. – Bangyou Aug 16 '14 at 11:12
  • 3
    @Wilf Thanks. Add a temporary user could be the best way to solve my problem. – Bangyou Aug 16 '14 at 11:14
  • 1
    I've never tried anything like this, but I would suspect you could boot from a live CD, move any directories/files, change the entry in /etc/passwd for the new home directory for your user and be good to go. Make backups of everything you intend to modify so you can put things back if it doesn't work as desired. – Joe Aug 24 '14 at 16:53
  • Not a duplicate since these options are not available on a remote server. – psusi Jun 06 '15 at 22:29

1 Answers1

1
  1. From your superuser account create a new superuser account. The easy way to do this is using the User Manager Application in your X-windows desktop. (https://help.ubuntu.com/community/AddUsersHowto) Just fillin the blanks and check the Administrator box.

  2. Exit the User Manager Application and close all other open windows. Log out of your user account and log in to the New Super User account using the standard login application that comes with your desktop. (you may have to fill in the account name for first time use.)

  3. As the New Super User, login to a terminal and enter the following commands: (You can probably use the File Manager Application but my system is based on the i7 CPU and an M.2 NVMe SSD that is 90 times faster than most. I am sorry you just can't be sure there was not a hick-up in the mouse drag and drop.)

    3.a Change to the root home folder: cd /home

    3.b. Create a backup of your home folder: sudo cp /home/MyUserName /home/MyUserName.bak

    3.c Create your new home folder location and delete the old home folder: sudo cp /home/MyUserName /media/MyUserName/MyDisk/MyUserName && sudo rm -R /home/MyUserName

    3.d Change your user name profile to the new home folder: sudo usermod -d /media/MyUserName/MyDisk/MyUserName MyUserName

    3.e Change the user owner and group to your user name and group: sudo chown -R MyUserName:MyUserName media/MyUserName/MyDisk/MyUserName

    3.f Create a link in the root home folder to your new folder: sudo ln -s /media/MyUserName/MyDisk/MyUserName /home/MyUserName
    && sudo chown -R MyUserName:MyUserName /home/MyUserName

  4. You may want to verify each of the commands after each execution. My personal favorite terminal command to verify security/owner information of files and links all at once is: ls -ltr path/folder. You can verify from the File Application as well (restart may be needed first).

  5. Exit all open windows and log out of the New Super User account.

  6. Log back in to your account and verify that the link works and the system home folder has changed.

  7. Optionally, delete the new superuser account and the backup copy.

John
  • 11
  • 1