尝试通过SSH连接到远程主机时出错 [英] Error while trying to connect via SSH to remote host

查看:201
本文介绍了尝试通过SSH连接到远程主机时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到远程主机以发出命令,但是在运行代码时出现以下错误消息:

I'm trying to connect to a remote host to issue a command, but I'm getting the following error message while running the code:

ssh:握手失败:ssh:没有通用的密钥交换算法;提供的客户端:[curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group14-sha1],服务器提供:[diffie-hellman-group1-sha1]应急:运行时错误:无效的内存地址或nil指针取消引用[signal SIGSEGV:细分违规代码= 0x1 addr = 0x10 pc = 0x759836]

ssh: handshake failed: ssh: no common algorithm for key exchange; client offered: [curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group14-sha1], server offered: [diffie-hellman-group1-sha1]panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x759836]

这是我正在使用的代码:

Here is the code that I'm using:

func (SSHClient *SSH) Connect(mode int) {
    var SSHConfig *ssh.ClientConfig
    var auth []ssh.AuthMethod

    if mode == CERT_PUBLIC_KEY_FILE {
        auth = []ssh.AuthMethod{SSHClient.readPublicKeyFile(SSHClient.Cert)}
    }

    SSHConfig = &ssh.ClientConfig{
        User:            SSHClient.User,
        Auth:            auth,
        HostKeyCallback: ssh.InsecureIgnoreHostKey(),
        Timeout:         time.Second * DEFAULT_TIMEOUT,
    }

    SSHConfig.Config.Ciphers = append(SSHConfig.Config.Ciphers, "diffie-hellman-group1-sha1")

    client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", SSHClient.IP, SSHClient.Port), SSHConfig)

    if err != nil {
        fmt.Printf("ERROR - While trying to Dial to the host %s with error: %s", SSHClient.IP, err.Error())
        return
    }

    session, err := client.NewSession()
    if err != nil {
        fmt.Printf("ERROR - While trying to create a new session on host %s with error: %s", SSHClient.IP, err.Error())
        client.Close()
        return
    }

    SSHClient.session = session
    SSHClient.client = client
}

关于如何解决此问题的任何想法?

Any ideas on how to resolve this issue?

谢谢.

推荐答案

问题是....服务器只愿意通过diffie-hellman-group1-sha1进行通话

The problem is.... the server is only willing to talk over diffie-hellman-group1-sha1

并且:

  • golang/go issue 2903: ssh: add diffie-hellman-group1-sha1, has been closed 6 days ago
  • golang/go/issue 17230: proposal: x/crypto/ssh: support Diffie-Hellman Group Exchange from RFC 4419, is being implemented now.

因此,您需要为客户提供 golang.org/x/crypto/ssh 的分支,例如提交39a91b 提交fe5e4ff 确实增加了对diffie-hellman-的支持group1-sha1.
或安装最新版本的 golang/crypto ,其中包括提交57b3e21 .

So you would need for your client a fork of golang.org/x/crypto/ssh, like bored-engineer/ssh, where commit 39a91b and commit fe5e4ff does add support for diffie-hellman-group1-sha1.
Or install the latest of golang/crypto, which includes commit 57b3e21.

这篇关于尝试通过SSH连接到远程主机时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆