User Home in WSL 2 vs Windows User Confusion

I have a bit of a confusion using WSL 2 on my Windows 10 machine regarding user names.

When I installed Windows 10 using my Microsoft Account, it created the user phili.

When I am in a powershell, the user home defaults to: C:\Users\phili\ which is /mnt/c/Users/phili/.ssh in WSL bash.

When I go to bash on WSL and cd ~ I end up in /home/phil.

The username in WSL seems to be phil which is different from the Windows username phili. I am not sure but I might have picked phil when installing WSL.


The problem I have is, that when I try to SSH into my WSL from my Macbook with ssh phil@<windows-host-ip> it won't accept my password (I have tried to change the pw also, no success). I can only login with ssh phili@<windows-host-ip> and my Windows password.

If I install the public key on my windows machine from my Macbook using ssh-copy-id phili@<windows-host-ip> it places them in /home/phil/.ssh/authorized_keys and not in C:\Users\phili\.ssh\authorized_keys.

EDIT: The files in /mnt/c/Users/phili/ are owned by user phil

phil@PHIL-DESKTOP:/mnt/c/Users/phili/.ssh$ ls
total 0
-rwxrwxrwx 1 phil phil  28 Oct  3 14:39 authorized_keys

Of course I could copy the public key manually, but this is not the point.

How can I clear up this mess with those usernames?

  • change the username in WSL to phili?
  • change the username in Windows from phili to phil?

I would prefer to use the username phil if possible.

Thanks for any tips.


Solution 1:

Some notes on usernames and home directories

  • WSL has a username, and Windows has a user name. They do not have to be the same, of course. And that's not a problem at all (nor related to your problem).

  • A WSL/Linux user has a home directory. By default, this is /home/<username>, but that does not have to be the case. In your case, it is, of course. Your WSL username is phil and your WSL/Linux home directory is /home/phil.

  • A Windows user has a home/profile directory that is (by default) named after the Microsoft Account for that user. And no, I don't find that ideal either. When I create my user on Windows, I first create it as a local user (not with a Microsoft account) so that it will set my username and the directory name the same. Then I convert my login to use the Microsoft account.

    This will become more difficult in Windows 11. My understanding is that it will require Windows 11 Pro or higher, but I'm not sure. When installing Win 11 Pro in a VM, I did my initial install with no network so that it could not use the Microsoft account.

  • Changing the username in Windows is easy. Changing the profile directory, not as much. I haven't tried it in a while, but according to this page there are Registry settings that use the Profile folder, so you'll have to muck with the Windows Registry in order to accomplish that.

    The alternative, as covered in this answer is to create a new user in Windows using a local account. Then copy everything over.

  • But regardless, changing the username isn't the solution to your problem. The main "issue" here is that Windows and WSL/Linux have different home directories. And you should not make these the same.

    You absolutely can't make Windows use your WSL/Linux home directory, since WSL/Linux is on a "virtualized" drive that lives in your Windows profile directory (%userprofile%\AppData\Local\Packages\<DistroPackage>\LocalState).

    You absolutely shouldn't make your WSL distribution use your Windows home directory. The Linux home directory should be on a Linux filesystem. For WSL, this is ext4. Putting your home directory on an NTFS drive will result in permission issues (somewhat resolvable, but not recommended) and performance issues (not currently resolvable).

Windows/Linux permission boundaries

The files in /mnt/c/Users/phili/ are owned by user phil

Well, actually no. The Windows drive is mounted by WSL with phil being the owner of the drive. That's why running ls in Linux shows your Linux user as the owner.

In PowerShell, run:

(Get-Acl C:\users\phili\).Owner
(Get-Acl C:\users\phili\).Access

And you'll see that SYSTEM is actually the Windows owner, and Windows user phili has full control.


ssh into WSL

I can only login with ssh phili@ and my Windows password.

This means to me that you have Windows OpenSSH installed. That's a good thing, as that's part of my recommended solution for sshing into WSL2 anyway.

I'm a bit confused that ssh-copy-id would have placed the files in your WSL/Linux home, though. ssh-copy-id should connect to the same server that ssh does (Windows OpenSSH in this case). Your ls command does show the authorized_keys in C:\Users\phili\, so perhaps you just have the directory names reversed?

Or perhaps you used these instructions for changing your Windows OpenSSH shell to WSL? That would explain it as well, since ssh-copy-id would place the files in the WSL/Linux OpenSSH location, but it's really the Windows OpenSSH that is handling things. In this case, the answer really is to just move the files over from /home/phil/.ssh/authorzied_keys to C:\Users\phili\.ssh\authorized_keys. By changing the registry setting for OpenSSH, you would "confuse" any client attempting to ssh-copy-id.

For some other options to ssh into WSL2, though, see my answer here.