目前我正在尝试使用 golang 连接到 ssh。 我在服务器上启用了 PasswordAuthentication 并通过终端连接来测试它 像魅力一样工作,完全没有问题。最终目标是通过 ssh 隧道连接到 MySQL 数据库。
sshConfig := &ssh.ClientConfig{
User: os.Getenv("SSH_USER"),
Auth: []ssh.AuthMethod{
ssh.Password(""),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
conn, err := ssh.Dial("tcp", "", sshConfig)
if err != nil {
return nil, err
}
凭据是通过环境变量加载的,它们也有效。
但是 ssh.Dial 函数总是抛出以下错误:
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
我错过了什么吗?
提前致谢。