我正在尝试连接到远程主机以发出命令,但在运行代码时出现以下错误消息:
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:分段违规code=0x1 addr=0x10 pc=0x759836]
这是我使用的代码:
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:分段违规code=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-sha1
与diffie-hellman-group1-sha1
之间的不匹配。尽管所有错误都已经处理完毕,但我不确定为什么你会在那里遇到panic
。 - Azeem