This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
ssh: handshake failed: knownhosts: key is unknown #637
Open
Description
I am a newbie with golang, when I tried to write git related codes with go, I failed to clone repo with ssh url.
The error is ssh: handshake failed: knownhosts: key is unknown
I'm sure:
- the
id_rsa.pem
can be read, and the path is correct. - I have added the public key in my git account.
here is the commands that I executed to create pem:
openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
chmod 700 id_rsa.pem
the id_rsa
is created by this, with no password:
ssh-keygen -t rsa -C "casa"
below is the whole code I wrote to clone a repo with ssh url:
package main
import (
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
"log"
)
func main() {
auth, err := ssh.NewPublicKeysFromFile("casa", "/Users/casa/.ssh/id_rsa.pem", "")
checkerr(err)
_, err = git.PlainClone("/Users/casa/Playground/git_go_test/test", false, &git.CloneOptions{
URL: "git@github.com:casatwy/HandyAutoLayout.git",
Auth: auth,
})
checkerr(err)
}
func checkerr(err error) {
if err != nil {
log.Fatal(err)
}
}
could you give some advice to me, or show a code example? I have searched a lot and have read the issue #550 , but find no help.