feat: use default ssh key

This commit is contained in:
fengcaiwen
2023-09-27 08:32:56 +08:00
committed by naison
parent bf3aa66d22
commit 1af3d0ba0f

View File

@@ -118,7 +118,12 @@ func DialSshRemote(conf *SshConfig) (*ssh.Client, error) {
remote, err = jumpRecursion(conf.ConfigAlias)
} else {
var auth []ssh.AuthMethod
if conf.Keyfile != "" {
if conf.Password != "" {
auth = append(auth, ssh.Password(conf.Password))
} else {
if conf.Keyfile == "" {
conf.Keyfile = filepath.Join(homedir.HomeDir(), ".ssh", "id_rsa")
}
var keyFile ssh.AuthMethod
keyFile, err = publicKeyFile(conf.Keyfile)
if err != nil {
@@ -126,9 +131,7 @@ func DialSshRemote(conf *SshConfig) (*ssh.Client, error) {
}
auth = append(auth, keyFile)
}
if conf.Password != "" {
auth = append(auth, ssh.Password(conf.Password))
}
// refer to https://godoc.org/golang.org/x/crypto/ssh for other authentication types
sshConfig := &ssh.ClientConfig{
// SSH connection username