Return error when ssh key does not exist
This commit is contained in:
parent
f2ab51a314
commit
994ceca1d1
@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -71,16 +72,21 @@ func makeConfig(info *shared.SSHInfo) (*ssh.ClientConfig, error) {
|
||||
keyPath = expandKeyPath(keyPath)
|
||||
}
|
||||
|
||||
if fileExists(keyPath) {
|
||||
if !fileExists(keyPath) {
|
||||
return nil, errors.New("ssh public key not found at " + keyPath)
|
||||
}
|
||||
|
||||
// Appen public key authentication method
|
||||
key, err := parsePrivateKey(keyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
methods = append(methods, ssh.PublicKeys(key))
|
||||
}
|
||||
|
||||
// Append password authentication method
|
||||
if info.Password != "" {
|
||||
methods = append(methods, ssh.Password(info.Password))
|
||||
}
|
||||
|
||||
cfg := &ssh.ClientConfig{
|
||||
User: info.User,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// SSHInfo contains ssh server configuration
|
||||
type SSHInfo struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
Port string `json:"port,omitempty"`
|
||||
|
Loading…
x
Reference in New Issue
Block a user