Don’t want to copy over your ssh keys from Windows to WSL Linux? Or generate new ones? Then share your Windows OpenSSH key with WSL! The OpenSSH config gives you the option to share keys using an IdentityFile directive. Here is how you can share your keys between Windows 10 and WSL.
The SSH config directive IdentityFile specifies a file from which the user’s DSA, ECDSA, authenticator-hosted ECDSA, Ed25519, authenticator hosted Ed25519 or RSA authentication identity is read. You can use this to share your Windows OpenSSH key with WSL. Assuming you’ve created a key pair in Windows using
First start with creating a symlink in WSL from
/mnt/c/Users/exampleuser/.ssh/. Substitute “exampleuser” with your user name:
ln -s /mnt/c/Users/exampleuser/.ssh ~/.ssh
Next, open up your ssh config file in Windows, which is located in C:\Users\exampleuser\.ssh, and add two IdentityFile lines. One using your Windows path and one the WSL Linux path:
Host *.example.org IdentityFile c:/users/exampleuser/.ssh/id_ed25519 IdentityFile /mnt/c/Users/exampleuser/.ssh/id_ed25519 User exampleuser ForwardAgent yes
Protip: ForwardAgent specifies whether the connection to the authentication agent (if any) will be forwarded to the remote machine. If you have the ssh-agent service is running in Windows, you can use this to connect to a host where you don’t have an authorized_keys available yet by ssh’ing into a jump host. Use with caution.