去连接到 ssh 结果握手失败

时间:2021-03-16 22:46:46

标签: go ssh

目前我正在尝试使用 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
  1. 我检查了 /etc/ssh/sshd_config
  2. 我尝试通过终端使用相同的身份验证方法,并且成功
  3. 我检查了凭据

我错过了什么吗?

提前致谢。

0 个答案:

没有答案