使用golang.org/x/crypto/ssh连接Arista EOS交换机时认证失败的问题求助
golang.org/x/crypto/ssh连接Arista EOS交换机时认证失败的问题求助
我最近在尝试用golang.org/x/crypto/ssh包连接Arista EOS交换机,目的是登录设备后执行指定命令并获取输出。这套代码在连接常规Linux设备时完全正常,但连接EOS交换机时却一直报认证失败的错误:
error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none], no supported methods remain
先贴出我的实现代码:
func ExecuteCommands(commands []string) string { config := &ssh.ClientConfig{ User: n.Username, Auth: []ssh.AuthMethod{ ssh.Password(n.Password), }, HostKeyCallback: ssh.InsecureIgnoreHostKey(), } client, err := ssh.Dial("tcp", n.IpAddress + ":" + n.Port, config) if err != nil { msg := fmt.Sprintf("Failed to connect to host: %v on port 22, error: %v, Username: %v, Password: %v", n.IpAddress, err, n.Username, n.Password) return msg } defer client.Close() session, err := client.NewSession() if err != nil { msg := fmt.Sprintf("Failed to create a session with client: %v", err.Error()) return msg } defer session.Close() stdin, err := session.StdinPipe() if err != nil { log.Fatalf("Unable to setup stdin for session: %v", err) } stdout, err := session.StdoutPipe() if err != nil { log.Fatalf("Unable to setup stdout for session: %v", err) } stderr, err := session.StderrPipe() if err != nil { log.Fatalf("Unable to setup stderr for session: %v", err) } output := "" // Start the remote shell if err := session.Shell(); err != nil { log.Fatalf("Failed to start shell: %v", err) } // Goroutine to read stdout go func() { scanner := bufio.NewScanner(stdout) for scanner.Scan() { output += scanner.Text() } }() // Goroutine to read stderr go func() { scanner := bufio.NewScanner(stderr) for scanner.Scan() { output += scanner.Text() } }() // Send commands writer := bufio.NewWriter(stdin) for _, cmd := range commands { _, err := writer.WriteString(cmd + "\n") if err != nil { log.Printf("Error writing command: %v", err) break } writer.Flush() time.Sleep(500 * time.Millisecond) // Give time for output to appear } // Close stdin to signal end of input stdin.Close() session.Wait() return output }
我怀疑是golang.org/x/crypto/ssh包的某些配置项没有适配Arista EOS的SSH服务逻辑,但翻了很久文档也没找到明确的配置方向。有没有遇到过类似问题的朋友,或者熟悉这个包和EOS设备的大佬能给点排查思路或解决方案?
内容来源于stack exchange
相关产品推荐
相关产品推荐

