我可以使用两个文件通过 SSH(使用 openssh 客户端)连接到我的服务器:~/.ssh/id_ed25519{,-cert.pub}
debug1: Trying private key: /home/xavier/.ssh/id_ed25519
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Offering ED25519-CERT public key: /home/xavier/.ssh/id_ed25519
debug1: Server accepts key: pkalg ssh-ed25519-cert-v01@openssh.com blen 441
debug1: sign_and_send_pubkey: no separate private key for certificate "/home/xavier/.ssh/id_ed25519"
debug1: Authentication succeeded (publickey).
我想要一个做同样事情的 go 客户端,但我不知道如何将该文件合并到https://godoc.org/golang.org/x/crypto/ssh#example-PublicKeysid_ed25519-cert.pub的示例中
key, err := ioutil.ReadFile("/home/xavier/.ssh/id_ed25519")
if err != nil {
log.Fatalf("unable to read private key: %v", err)
}
// Create the Signer for this private key.
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
log.Fatalf("unable to parse private key: %v", err)
}
config := &ssh.ClientConfig{
User: "user",
Auth: []ssh.AuthMethod{
// Use the PublicKeys method for remote authentication.
ssh.PublicKeys(signer),
},
}
// Connect to the remote server and perform the SSH handshake.
client, err := ssh.Dial("tcp", "host.com:22", config)
if err != nil {
log.Fatalf("unable to connect: %v", err)
}
defer client.Close()
部分问题是我不知道这个文件是什么(PublicKey?证书?),部分问题是即使我知道我也不明白它在这个交换中的作用。
我已确认此文件是必需的:删除它会导致 ssh CLI 失败。
至尊宝的传说
相关分类