golang: ssh: handshake failed: EOF

I wrote a go project to deploy online code. I need to remote machine and run some start reload like command.

I have 200+ machines, so I use go routine to do this job.

The problem is sometimes ssh failure throw ssh: handshake failed: EOF or ssh: handshake failed: read tcp 10.19.177.216:44721->10.19.139.36:22: read: connection reset by peer why ?

My core code:

func RunRemoteCmd(selfDesc string, host string, cmd string, ch chan<- RunResult) { startTime := time.Now() sshConfig := &ssh.ClientConfig{ User: "root", Auth: []ssh.AuthMethod{ publicKey, }, HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error { return nil }, } addr := fmt.Sprintf("%s:22", host) connection, err := ssh.Dial("tcp", addr, sshConfig) if err != nil { ch <- RunResult{selfDesc, err.Error(), "", time.Since(startTime)} return } session, err := connection.NewSession() if err != nil { ch <- RunResult{selfDesc, err.Error(), "", time.Since(startTime)} return } defer session.Close() var out bytes.Buffer session.Stdout = &out session.Run(cmd) ch <- RunResult{selfDesc, "", out.String(), time.Since(startTime)} } 
1

1 Answer

Maybe multiple ssh connection refuse by remote server.

I change one server one connection and muliple NewSession fixed this problem.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like