Allow all three auth types
This commit is contained in:
22
src/ssh.go
22
src/ssh.go
@ -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)
|
||||||
|
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
|
// 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 {
|
||||||
|
Reference in New Issue
Block a user