13

I'm trying to move from using Powershell to Bash on Windows (Windows Subsystem for Linux or WSL). For the purpose of using GIT, I've set up my SSH keys in C:/Users/User/.ssh. I then logged into Bash, and created a symlink ln -s /mnt/c/Users/User/.ssh/ ~/.ssh/ in order to (in theory) use the same ssh keys from both shells.

When running git, however, I always get an error: Bad owner or permissions on /home/user/.ssh/config. What am I doing wrong?

7

What am I doing wrong?

SSH requires sane permissions on the private keys and you are not able to achieve that while symlinking to different filesystem (windows). The manual page for ssh explains that quite clearly:

~/.ssh/id_rsa

Contains the private key for authentication. These files contain sensitive data and should be readable by the user but not accessible by others (read/write/execute). ssh will simply ignore a private key file if it is accessible by others.

You can most probably copy the private keys and set appropriate permissions, if you want to "share the keys".

2
  • thank you. And there is no way I could share the same user between the two systems?
    – bluppfisk
    Feb 28 '17 at 3:01
  • copying the keys doesn't work. they still have their old ownership & permissions. Using chmod and chown silently fails.
    – Hippyjim
    May 12 '17 at 14:40
5

You need to mount your windows filesystem using the DrvFS file system with the metadata option which allows Linux permissions to coexist with Windows files by storing them in file metadata.

sudo umount /mnt/c sudo mount -t drvfs C: /mnt/c -o metadata

This will allow you to use your SSH Keys across both Operating Systems.

Further reading: https://blogs.msdn.microsoft.com/commandline/2018/01/12/chmod-chown-wsl-improvements/

And yet more reading on how to configure WSL to apply this setting everytime it starts: https://blogs.msdn.microsoft.com/commandline/2018/02/07/automatically-configuring-wsl/

5
  • Hi Chad, this is interesting. I no longer have a dual boot system so I'm unable to test if it works for me and therefore can't mark it as the right answer. But I can upvote.
    – bluppfisk
    Jun 28 '18 at 11:30
  • @bluppfisk fwiw I am using this method to share ssh keys across Windows/Linux and it is working great!
    – ChadT
    Jun 29 '18 at 0:10
  • just to be clear, you are still simply copying the files not sharing them, right? As Jakuje notes, the permissions of symlinks seem incompatible with ssh restrictions and I have just encountered the expected "unprotected file" warnings... If you're able to somehow keep only one key in either WSL or Windows and then create a shortcut/symlink that works with SSH, please do let me know!
    – Fons MA
    Jun 20 at 2:57
  • @FonsMA - No this isn't copying, it's mounting the files with additional metadata to that the permission info is carried through.
    – ChadT
    Jun 21 at 0:59
  • yes, my C drive has Linux metadata and I can set whatever permissions I want. But I still need to keep an exact copy of my_key.rsa both under /mnt/c/Users/fons/.ssh/ and /home/fons/.ssh/ for stuff I run out of WSL (like my Rstudio Server ssh tunnelling) and stuff that runs on Windows (like Visual Studio Code). Am I missing something?
    – Fons MA
    Jun 21 at 1:32

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.