Changing home directory of user on Windows Subsystem for Linux
Changing the home directory with WSL is done the same way as in Linux:
- Enter bash
- Type the command
sudo vim /etc/passwd
- Find your account's line, which might look like:
harry:x:1000:1000:"",,,:/home/harry:/bin/bash
- 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) - Save the file and exit vim by typing
:wq
and press Enter - Exit bash and re-launch it
- To test, use the commands:
cd ~
pwd
Let me know if you need more information.
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
)