ssh: must specify HostKeyCallback
Closed this issue · 0 comments
songtianyi commented
go version
go version go1.8 darwin/amd64
ssh version
OpenSSH_7.3p1, LibreSSL 2.4.1
code went wrong
package main
import (
"fmt"
"golang.org/x/crypto/ssh"
"log"
"github.com/Juniper/go-netconf/netconf"
)
func main() {
sshConfig := &ssh.ClientConfig{
Config: ssh.Config{
Ciphers: []string{"aes128-cbc", "hmac-sha1"},
},
User: "root",
Auth: []ssh.AuthMethod{ssh.Password("xxxx")},
}
s, err := netconf.DialSSH("172.16.240.189", sshConfig)
if err != nil {
log.Fatal(err)
}
defer s.Close()
fmt.Println(s.ServerCapabilities)
fmt.Println(s.SessionID)
reply, err := s.Exec(netconf.MethodGetConfig("running"))
if err != nil {
panic(err)
}
fmt.Printf("Reply: %+v", reply)
}
it still went wrong even if i added the HostKeyCallback
package main
import (
"fmt"
"golang.org/x/crypto/ssh"
"log"
"net"
"github.com/Juniper/go-netconf/netconf"
)
func main() {
sshConfig := &ssh.ClientConfig{
Config: ssh.Config{
Ciphers: []string{"aes128-cbc", "hmac-sha1"},
},
User: "root",
Auth: []ssh.AuthMethod{ssh.Password("xxx")},
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
s, err := netconf.DialSSH("172.16.240.189", sshConfig)
if err != nil {
log.Fatal(err)
}
defer s.Close()
fmt.Println(s.ServerCapabilities)
fmt.Println(s.SessionID)
reply, err := s.Exec(netconf.MethodGetConfig("running"))
if err != nil {
panic(err)
}
fmt.Printf("Reply: %+v", reply)
}