From d6c1402223533c83b2159f5001120a19ada6afe9 Mon Sep 17 00:00:00 2001 From: Louis Ruch Date: Thu, 21 Jul 2022 15:07:01 -0700 Subject: [PATCH] bug(cli): Correctly generate private key file (#2274) --- internal/cmd/commands/connect/ssh.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/cmd/commands/connect/ssh.go b/internal/cmd/commands/connect/ssh.go index bf7e309d4f..2755439847 100644 --- a/internal/cmd/commands/connect/ssh.go +++ b/internal/cmd/commands/connect/ssh.go @@ -111,6 +111,12 @@ func (s *sshFlags) buildArgs(c *Command, port, ip, addr string, creds credential } return nil }) + // SSH requires the private key file to end with a newline. + // When injesting a ssh_private_key from a file:// Boundary calls strings.TrimSpace + // which will also trim newlines. + if !strings.HasSuffix(privateKey, "\n") { + privateKey = fmt.Sprintln(privateKey) + } _, err = pkFile.WriteString(privateKey) if err != nil { return nil, nil, credentials{}, fmt.Errorf("Error writing private key file to %s: %w", pkFile.Name(), err)