Allow all three auth types

This commit is contained in:
Pim van Pelt
2025-07-06 22:16:01 +02:00
parent 96c7c3aeaa
commit 1afa1e6d43

View File

@ -135,7 +135,7 @@ func (rb *RouterBackup) Connect() error {
} }
// If SSH agent didn't work, try key file // If SSH agent didn't work, try key file
if len(config.Auth) == 0 && keyFile != "" { if keyFile != "" {
// Expand ~ in keyFile path // Expand ~ in keyFile path
if strings.HasPrefix(keyFile, "~/") { if strings.HasPrefix(keyFile, "~/") {
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
@ -145,21 +145,19 @@ func (rb *RouterBackup) Connect() error {
} }
key, err := ioutil.ReadFile(keyFile) key, err := ioutil.ReadFile(keyFile)
if err != nil { if err == nil {
return fmt.Errorf("unable to read private key: %v", err)
}
signer, err := ssh.ParsePrivateKey(key) signer, err := ssh.ParsePrivateKey(key)
if err != nil { if err != nil {
return fmt.Errorf("unable to parse private key: %v", err) fmt.Errorf("unable to parse private key: %v", err)
} else {
config.Auth = append(config.Auth, ssh.PublicKeys(signer))
}
} }
config.Auth = []ssh.AuthMethod{ssh.PublicKeys(signer)}
} }
// Fall back to password if available // Fall back to password if available
if len(config.Auth) == 0 && rb.password != "" { if rb.password != "" {
config.Auth = []ssh.AuthMethod{ssh.Password(rb.password)} config.Auth = append(config.Auth, ssh.Password(rb.password))
} }
if len(config.Auth) == 0 { if len(config.Auth) == 0 {