-
Notifications
You must be signed in to change notification settings - Fork 822
Description
Consider the following example ssh config:
Host example.com
Hostname ssh.example.com
When openssh is used to connect to example.com
through a non-default port, it will properly honor the non-default port and only replace the hostname with ssh.example.com
, e.g.:
$ ssh -p 2222 example.com
This will connect to ssh.example.com via port 2222.
Also, using git to clone the url ssh://git@example.com:2222/my-repo
will properly handle this the expected way.
The same URL however will cause go-git to unexpectedly switch to port 22. This happens in doGetHostWithPortFromSSHConfig
, which uses DefaultSSHConfig.Get
to retrieve the user config port. This will however not find a match in the config (as there is no Port
for the host) and thus return the default value 22
for it, causing the unexpected port override.
To fix this, a change in the dependent https://github.com/kevinburke/ssh_config library is required, as it's currently not possible to check if a value exists, which is needed to decide if the port should be overridden or not. I'll link the issue that I'm going to create in the library here later. EDIT here it is
Another inconsistency that I found in the same function is that doGetHostWithPortFromSSHConfig
will ignore Port
in case no Hostname
is configured. My understanding (without having it verified) of the ssh config is that you should be able to override the port without overriding the hostname.