我正在尝试连接到远程主机以发出命令,但在运行代码时收到以下错误消息:
ssh:握手失败:ssh:没有通用的密钥交换算法;客户提供:[[电子邮件受保护] /cdn-cgi/l/email-protectionecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group14-sha1],服务器提供:[diffie-hellman-group1-sha1]恐慌:运行时错误:无效的内存地址或 nil 指针取消引用
[信号SIGSEGV:分段违规代码=0x1 addr=0x10 pc=0x759836]
这是我正在使用的代码:
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
}
关于如何解决这个问题有什么想法吗?
提前致谢。
问题是......服务器只愿意通过 diffie-hellman-group1-sha1 进行对话
And:
-
golang/go 问题 2903 https://github.com/golang/go/issues/2903: ssh: 添加 diffie-hellman-group1-sha1, 已于 6 天前关闭
-
golang/go/问题 17230 https://github.com/golang/go/issues/17230: 提议:
x/crypto/ssh
:支持来自 RFC 4419 的 Diffie-Hellman Group Exchange,现已实施。
所以你需要为你的客户提供一个叉子golang.org/x/crypto/ssh
, like 无聊工程师/ssh https://github.com/bored-engineer/ssh/, where 提交 39a91b https://github.com/bored-engineer/ssh/commit/39a91b2f99659c746b120025dff1a4fb46b380b7 and 提交 fe5e4ff https://github.com/bored-engineer/ssh/commit/fe5e4ff9a3592bf7c231b4ed160298c8c4a04c57确实添加了对 diffie-hellman-group1-sha1 的支持。
或者安装最新的golang/crypto https://github.com/golang/crypto, 包括提交 57b3e21 https://github.com/golang/crypto/commit/57b3e21c3d5606066a87e63cfe07ec6b9f0db000.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)