解决golang ssh包报错 ssh: must specify HostKeyCallback

client, err := ssh.Dial("tcp", "192.168.1.71:22", &ssh.ClientConfig{
        User: "kevin",
        Auth: []ssh.AuthMethod{
            ssh.Password("123456"),
        },
        //需要验证服务端,不做验证返回nil就可以,点击HostKeyCallback看源码就知道了
        HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
            return nil
        },
    })
    fmt.Println(err)
    fmt.Println(client)

标签: golang