From 1afa1e6d435db06d20ee3c24724e8a9cd01b6314 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sun, 6 Jul 2025 22:16:01 +0200 Subject: [PATCH] Allow all three auth types --- src/ssh.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ssh.go b/src/ssh.go index 44b1225..f0bfc80 100644 --- a/src/ssh.go +++ b/src/ssh.go @@ -135,7 +135,7 @@ func (rb *RouterBackup) Connect() error { } // If SSH agent didn't work, try key file - if len(config.Auth) == 0 && keyFile != "" { + if keyFile != "" { // Expand ~ in keyFile path if strings.HasPrefix(keyFile, "~/") { homeDir, err := os.UserHomeDir() @@ -145,21 +145,19 @@ func (rb *RouterBackup) Connect() error { } key, err := ioutil.ReadFile(keyFile) - if err != nil { - return fmt.Errorf("unable to read private key: %v", err) + if err == nil { + signer, err := ssh.ParsePrivateKey(key) + if err != nil { + fmt.Errorf("unable to parse private key: %v", err) + } else { + config.Auth = append(config.Auth, ssh.PublicKeys(signer)) + } } - - signer, err := ssh.ParsePrivateKey(key) - if err != nil { - return fmt.Errorf("unable to parse private key: %v", err) - } - - config.Auth = []ssh.AuthMethod{ssh.PublicKeys(signer)} } // Fall back to password if available - if len(config.Auth) == 0 && rb.password != "" { - config.Auth = []ssh.AuthMethod{ssh.Password(rb.password)} + if rb.password != "" { + config.Auth = append(config.Auth, ssh.Password(rb.password)) } if len(config.Auth) == 0 {