diff --git a/services.go b/services.go index 428f8a6..528338b 100644 --- a/services.go +++ b/services.go @@ -13,10 +13,11 @@ import ( type Services struct { cfg config + keyFileName string } func NewServices(cfg config) *Services { - return &Services{cfg: cfg} + return &Services{cfg: cfg, keyFileName: "id_ecdsa"} } func (s *Services) AddPrivateKey() error { @@ -26,7 +27,8 @@ func (s *Services) AddPrivateKey() error { return err } - if err := writeFile(`${HOME}/.ssh/id_rsa`, s.cfg.PrivateKey, 0400); err != nil { + privateKey := strings.TrimSpace(s.cfg.PrivateKey) + "\n" + if err := writeFile(`${HOME}/.ssh/` + s.keyFileName, privateKey, 0400); err != nil { return err } @@ -40,9 +42,11 @@ func (s *Services) ConfigureSSH() error { if err := sshConfigTemplate.Execute(&bfr, struct { Cfg config Home string + KeyFileName string }{ Cfg: s.cfg, Home: os.Getenv("HOME"), + KeyFileName: s.keyFileName, }); err != nil { return err } @@ -115,7 +119,7 @@ func runCmdExpectingOutput(cmd ...string) (string, error) { func writeFile(path string, content string, mode os.FileMode) error { fullPath := os.ExpandEnv(path) - log.Printf(" .. [file] %v (%v bytes)", fullPath, len(content)) + log.Printf(" .. [file] %v (%v bytes)", fullPath, len(content)) return os.WriteFile(fullPath, []byte(content), mode) } @@ -128,6 +132,6 @@ Host * Host {{.Cfg.HostName}} HostName {{.Cfg.HostName}} User dokku - IdentityFile {{.Home}}/.ssh/id_rsa + IdentityFile {{.Home}}/.ssh/{{.KeyFileName}} `)) )