Skip to content

Commit

Permalink
Add support for host keys for non-22 ports
Browse files Browse the repository at this point in the history
When not using the standard SSH port (22), the port is appended
to the hostname (in brackets) like so: "host" -> "[host]:1234"

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Oct 25, 2020
1 parent 9f6d6ba commit 8794e8d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/bindings/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,23 @@ func sshClient(_url *url.URL, secure bool, passPhrase string, identity string) (
authMethods = append(authMethods, ssh.Password(string(pass)))
}

port := _url.Port()
if port == "" {
port = "22"
}

callback := ssh.InsecureIgnoreHostKey()
if secure {
key := terminal.HostKey(_url.Hostname())
host := _url.Hostname()
if port != "22" {
host = fmt.Sprintf("[%s]:%s", host, port)
}
key := terminal.HostKey(host)
if key != nil {
callback = ssh.FixedHostKey(key)
}
}

port := _url.Port()
if port == "" {
port = "22"
}

bastion, err := ssh.Dial("tcp",
net.JoinHostPort(_url.Hostname(), port),
&ssh.ClientConfig{
Expand Down

0 comments on commit 8794e8d

Please sign in to comment.