For some reason Golang SSH client can't connect to my EC2 instance. It throws the following error:
ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
这是我的代码:
package main
import (
"fmt"
"github.com/helloyi/go-sshclient"
)
func main() {
client, err := sshclient.DialWithKey("ip:port", "ubuntu", "my_key.pem")
if err != nil {
fmt.Println(err)
return
}
out, err := client.Cmd("help").Output()
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(out))
}
有趣的是,当我在另一台计算机上运行此代码时,连接没有出现任何错误.所以我认为这一定是电脑的问题,而不是我的代码.我还try 使用Paramiko客户端在Python中连接实例,它工作得非常完美.当然,我试着在CMD和MobaXTerm客户端中使用ssh
命令进行连接,这两个命令都有效.我try 使用其他Golang SSH客户端golang.org/x/crypto/ssh
,但没有成功(相同的错误).
谢谢你的帮助.