package main
import (
"fmt"
"golang.org/x/crypto/ssh"
)
func main() {
c := &ssh.ClientConfig{
User: "root",
Auth: []ssh.AuthMethod{
ssh.Password("123456"),
},
}
_, err := ssh.Dial("tcp", "192.168.0.219:22", c) // replace this
if err != nil {
fmt.Println(err)
return
}
}
执行报错,不知道什么原因?
go version go1.7.4
Centos 6.5系统
[root@host219 ~]# go run test.go
ssh: must specify HostKeyCallback
```
client, err := ssh.Dial("tcp", "192.168.1.71:22", &ssh.ClientConfig{
User: "kevin",
Auth: []ssh.AuthMethod{
ssh.Password("ajiao0106"),
},
//需要验证服务端,不做验证返回nil就可以,点击HostKeyCallback看源码就知道了
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
})
fmt.Println(err)
fmt.Println(client)
```
#1