我try 使用SSH和Go连接到我的一个虚拟机.
ssh root@my_host
我输入密码,一切正常.
package main
import (
"golang.org/x/crypto/ssh"
"fmt"
)
func connectViaSsh(user, host string, password string) (*ssh.Client, *ssh.Session) {
config := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{ssh.Password(password)},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
client, err := ssh.Dial("tcp", host, config)
fmt.Println(err)
session, err := client.NewSession()
fmt.Println(err)
return client, session
}
func main() {
client, _ := connectViaSsh("root", "host:22", "password")
client.Close()
}
如果我运行它,它会返回一个错误:
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none], no supported methods remain
有人知道是什么导致了这样的错误吗.在Python和shell中使用paramiko可以很好地工作,但在Go中失败.我有什么遗漏吗?