【发布时间】:2020-02-15 23:25:58
【问题描述】:
我正在尝试连接到远程主机以发出命令,但在运行代码时收到以下错误消息:
ssh:握手失败:ssh:没有通用的密钥交换算法;客户端提供:[curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 diffie-hellman-group14-sha1],服务器提供:[diffie-hellman-group1-sha1]panic:运行时错误:无效的内存地址或 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-group14-sha1vsdiffie-hellman-group1-sha1。尽管所有错误都已得到处理,但我不确定您为什么会在那里收到panic。 -
+1 用于提出与编程和开发有关的 SSH 问题。
-
@happugopher 问题解决了吗?
标签: go encryption ssh