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: handshake failed: ssh: no common algorithm for key exchange; client offered: [[email protected] 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?
Thanks in advance.
diffie-hellman-group14-sha1
vsdiffie-hellman-group1-sha1
. I'm not sure why you're getting thatpanic
there despite the fact that all the errors are already handled. – Azeem