domechomsky
domechomsky

Reputation: 413

git ssh from WSL unable to connect to our company's private internal git host

I'm trying to set up my PC so that I can commit to our company's internal github equivalent from within WSL so I can avoid losing focus when I have to shutdown WSL VS Code to push from Windows. The rsa_key is set correctly on both server side and in WSL (including 600 permissions)

If I run the following in Windows in gitbash:

ssh -p [default port for that site] myusername@[our_internal_git_host]

it connects successfully, but if I run the same command in WSL (WSL 1, Ubuntu), I get

ssh: Could not resolve hostname

But if I try the following as a test from wsl:

ssh [email protected]

It is able to connects and asks me about RSA keys, so ssh is not blocked from WSL entirely by my Windows firewall (which I don't have permission to configure, by the way)

This suggests to me that either this some security setting on the internal git host site that I can do nothing about, or more likely that it is a port forwarding issue.

To test if I'm correct, using the ssh command, I have to use something like ssh -L flag so that it uses the WSL outgoing port which is allowed for SSH to connect to public github, and but then uses the [default port for that site] to connect with it.

Then as a second step, I probably add something to a config file for open-ssh, git, or both in WSL to make that solution take effect when I try to run git push from WSL.

By the way, sorry about being vague about some specifics, just trying to be extra careful re: proprietary info and security concerns.

Does anyone have any ideas?

Upvotes: 4

Views: 2992

Answers (1)

domechomsky
domechomsky

Reputation: 413

TLDR:

add

[network]
generateHosts = false

to /etc/wsl.conf

Many months later, I finally got around to figuring this out.

It's an issue with a some DNS functionality that allows windows to find our internal git host that doesn't work in WSL with the default settings. So I did the following (this was a few days ago, and I was too busy at the time to come back and immediately write this answer, but I think this is the accurate process):

In WSL (assuming Ubuntu, probably works for Debian as well)

open /etc/wsl.conf with nano or editor or your choice (probably will need root to save, so easiest to just do with sudo nano /etc/wsl.conf)

add the following (to prevent wsl from automatically adding hostnames to /etc/resolv.conf) on startup:

[network]
generateHosts = false

Restart WSL by running wsl --shutdown in cmd and then relaunching wsl from terminal or VS code etc, navigate to a repo and run git fetch etc. to confirm if working (obviously, remote url settings etc. need to be correct, but if it's working from Windows, should now work from WSL as well)

By the way, I should add that while my question referenced SSH, I believe I'm using https for all the repos I've tried this with at the moment, but I imagine this same solution will work fine for SSH as long as the SSH keys are configured correctly in WSL and added in the git host.

(Note: an earlier version of this answer also involved checking the default gateway from Windows and manually adding that to /etc/resolv.conf, but after rechecking my work, that was not actually what finally managed to fix it)

Upvotes: 2

Related Questions