summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2020-10-25 14:43:27 +0100
committerAnders F Björklund <anders.f.bjorklund@gmail.com>2020-10-25 16:30:42 +0100
commit6f6cf87f8f651e2c7efd40a4c9fc1a0acb3c49bb (patch)
treefdaaadc71b33e231160f0fe3619a3e1c7ce6f724
parentbce8331528c186ef2234a3cfe6c7d0e09da79bdd (diff)
downloadpodman-6f6cf87f8f651e2c7efd40a4c9fc1a0acb3c49bb.tar.gz
podman-6f6cf87f8f651e2c7efd40a4c9fc1a0acb3c49bb.tar.bz2
podman-6f6cf87f8f651e2c7efd40a4c9fc1a0acb3c49bb.zip
Add support for host keys for non-22 ports
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 <anders.f.bjorklund@gmail.com> (cherry picked from commit 8794e8db1ce3088d633911454d6d36c4e939e126)
-rw-r--r--pkg/bindings/connection.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go
index 3a7662c41..31435ae91 100644
--- a/pkg/bindings/connection.go
+++ b/pkg/bindings/connection.go
@@ -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{