I have Putty and Git installed on Windows 10, and I'm also using WSL2 with Ubuntu 20.04 LTS. Sometimes I want to use SSH and Git from WSL2, other times in Windows. Everything works fine, except I have to duplicate my .gitconfig, .gitignore and .ssh files in both my Windows and WSL2 home directories.
I don't want to maintain this config in two places, so I thought I could symlink the files in WSL2:
# In /home/myuser on WSL2
ln -s /mnt/c/Users/myuser/.ssh
ln -s /mnt/c/Users/myuser/.gitconfig
ln -s /mnt/c/Users/myuser/.gitignore
This kind of works, except for a few problems.
- Files in
/mnt/chave0777permissions andchmodobviously doesn't do anything on them. When I usesshin WSL2, it complains about the key:Permissions 0777 for '/home/myuser/.ssh/id_rsa' are too open - In
.gitconfigI havecore.excludesfileset toC:\\\\Users\\myuser\\.gitignore, which works when using Git from Windows but not from WSL2. If I change it to/home/myuser/.gitignoreit works in WSL2 but not on Windows. I tried using the relative path.gitignoreand completely removing thecore.excludesfiledirective, but neither worked.
Does anyone know a work around to these issues? It did occur to me that Putty doesn't care about the SSH key permissions, so I could move the files to WSL2 and then update my Putty connections (I have a lot of them!) to access the keys via \\wsl$. However, that wouldn't solve the core.excludesfile problem and I'd prefer to maintain the config in Windows and access it in WSL2 via /mnt/c.
Additional Context
I'm converting my dev environment from Windows to WSL2, using PhpStorm and Docker for PHP development. I have switched Docker to use the WSL2 backend instead of Hyper-V and moved my project files (i.e. git repos) to WSL2. I then open the project in PhpStorm using the \\wsl$ share. All of this is working great and I love how much faster it is, but having to duplicate the git config and ssh keys is annoying.