I'd like to change the home directory of the user that I initially setup on Windows Subsystem for Linux. I found this command

sudo usermod -d /mnt/c/Users/Alex alex

Which should allow this, however I am getting this error

usermod: user alex is currently used by process 2

Presumably because I am logged in as that user. I've tried going to root by doing sudo su - and then running the command again but I get the same issue. I tried a command I found on Google to log out the user alex from root but that also kicked me out of bash entirely.

Any thoughts?

  • Can you not logout of that account, login as another account, and then run the commands to see what result you get? – Pillsbury IT Doughboy Oct 11 '16 at 20:53
  • Logging out of that account closes Linux bash and gets you back to Windows prompt. Logging back in just puts you by default in that user. And switching to root through sudo su - I still get the process error – Xeon06 Oct 11 '16 at 21:25
  • I see, I assume you cannot log into the Windows as another account while logged out of that one, and then run the bash command then from that account in bash for the other account? I've not setup bash within Windows yet so just thinking of potential simple solutions even though having to do that would be sort of inconvenient but if it's just a one-time deal then done, maybe it'd work. Quick thoughts only though. – Pillsbury IT Doughboy Oct 11 '16 at 23:25
  • Unfortunately the bash environment is tied to the current user Windows, stored in %appdata%. So another user will get their own bash environment – Xeon06 Oct 12 '16 at 14:43
  • You can change the default user name by executing in Windows (not bash) lxrun /setdefaultuser myusername. – harrymc Oct 12 '16 at 20:23

Changing the home directory with WSL is done the same way as in Linux:

  1. Enter bash
  2. Type the command sudo vim /etc/passwd
  3. Find your account's line, which might look like:
  4. Change the home directory, which above is /home/harry, to the new directory, using WSL notation (If you want to set Windows directory as home directory, you need to prepend it with /mnt/, like /mnt/c for C:/, /mnt/d for D:/, etc)
  5. Save the file and exit vim by typing :wq and press Enter
  6. Exit bash and re-launch it
  7. To test, use the commands:
    cd ~

Let me know if you need more information.

  • I don't know WSL, I'm just curious: in general is it safe to just vim /etc/passwd? In Linux we have vipw especially for the job. – Kamil Maciorowski Oct 13 '16 at 19:55
  • @KamilMaciorowski: I have just started with WSL, but I can say that sudo /usr/sbin/vipw does exactly the same as my point 2 above. Changing /etc/passwd is as safe as doing it on Linux. Maybe safer because destroying it does not affect Windows logon. – harrymc Oct 13 '16 at 20:00
  • Thank you! I don't know why the only way I could find to edit this was through usermod. – Xeon06 Oct 13 '16 at 22:02
  • 4
    Be careful with this - if you move out of the main fake linux filesystem, you'll find you can't edit file permissions properly. – Hippyjim May 12 '17 at 15:04
  • @Hippyjim I'm facing the same issue and find out that this SO anwser could help (requires Win 10 Insider Build 17063 and above). – Weekend Jul 14 '19 at 11:55

As at 2021, there's a better way to log in as root and change user's home directory:

  • Press Win + R
  • Enter cmd /C wsl -u root
  • A root terminal will open and now you can use the usermod -d <path> <user> command with no problem (e.g. usermod -d /mnt/c/Users/Alex alex)

You can try running lxrun /setdefaultuser root in command prompt, then change the directory, then change the default user to Alex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.