Change home of WSL to /mnt/c/Users/YourWindowsUser
What I'm trying to do
I tried to edit the home dir of the windows subsystem (in my case Ubuntu) to my default User in Windows. Why? Because I want to replace Cygwin or at least check if it's viable to replace Cygwin. Please let's focus on the how, not why. I'm also aware that commanding windows via the Subsystem can cause write/read permission issues AFAIK.
The problem(s)
I tried to modify passwd with vim, but I have read that this can cause issues and it's supposed to be far safer to manipulate it by commands. Luckily the command for the job exists:
sudo usermod --home /mnt/c/Users/User CurrentUser
However, when I enter it the output is:
usermod: user CurrentUser is currently used by process 4
But: process 4 is bash.
User@Machinename:~$ ps -A
PID TTY TIME CMD
1 ? 00:00:00 init
3 tty1 00:00:00 init
4 tty1 00:00:00 bash
39 tty1 00:00:00 ps
- When I kill (
kill -9 4
) it, the Subsystem dies, obviously. - When I try changing the user to root (
sudo -i
), it does not list CurrentUser when I enterwho
or any other "who is logged in"-type commands.
Has anyone figured out how to do this, that when I enter cd
in the subsystem, it brings me to /mnt/c/User/CurrentUser
?
What am I doing wrong?
Note:This is a repost of this question on SO since it was suggested I may find an answer here if I repost it. I'll just link it in case somebody finds one or the other resource and is led here since superuser is the right place for it.
Solution 1:
I found a better workaround by not logging in as USERNAME, but logging in as root (temporarily) instead. Here are the commands I used on my system, running ubuntu on a current Windows 10 build 19043.1165:
In an elevated PS prompt
PS C:\Windows\system32> ubuntu.exe config --default-user root
Start ubuntu, and run:
usermod --home /mnt/c/Users/SHORTNA~1/ USERNAME
- Note that if you have spaces in your windows username, you will need to use the path with the ~ in it. You can find it by opening a command prompt and using
dir /x
.
Next return to your elevated powershell and run:
PS C:\Windows\system32> ubuntu.exe config --default-user USERNAME
Next time you start your ubuntu shell, it should have the right home directory. If you're using another distro, you should have a similar command (opensuse-42, or sles-12 for example).