diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go index a3677d3932..48575c8598 100644 --- a/pkg/bindings/connection.go +++ b/pkg/bindings/connection.go @@ -91,9 +91,12 @@ func NewConnectionWithIdentity(ctx context.Context, uri string, identity string, var connection Connection switch _url.Scheme { case "ssh": - port, err := strconv.Atoi(_url.Port()) - if err != nil { - return nil, err + port := 22 + if _url.Port() != "" { + port, err = strconv.Atoi(_url.Port()) + if err != nil { + return nil, err + } } conn, err := ssh.Dial(&ssh.ConnectionDialOptions{ Host: uri, diff --git a/test/e2e/system_connection_test.go b/test/e2e/system_connection_test.go index 3c320778aa..729d92a606 100644 --- a/test/e2e/system_connection_test.go +++ b/test/e2e/system_connection_test.go @@ -281,6 +281,15 @@ var _ = Describe("podman system connection", func() { _, err = Start(cmd, GinkgoWriter, GinkgoWriter) Expect(err).ToNot(HaveOccurred()) + // export the container_host env var and try again + err = os.Setenv("CONTAINER_HOST", fmt.Sprintf("ssh://%s@localhost", u.Username)) + Expect(err).ToNot(HaveOccurred()) + defer os.Unsetenv("CONTAINER_HOST") + + cmd = exec.Command(podmanTest.RemotePodmanBinary, "ps") + _, err = Start(cmd, GinkgoWriter, GinkgoWriter) + Expect(err).ToNot(HaveOccurred()) + uri := url.URL{ Scheme: "ssh", User: url.User(u.Username),