-
Notifications
You must be signed in to change notification settings - Fork 543
can you give me a sample about clone a private repo using ssh key? #550
Comments
Hey @Gluoo, The existing example provided at For example:
|
@orirawlings , thanks for your quickly response.
you mean, I don't need add any ssh auth code in git.PlainClone function? Just eval But even if I follow your guide, I still got errors: "error creating SSH agent: "SSH agent requested but SSH_AUTH_SOCK not-specified" |
Hey @Gluoo, That is correct. The library will dispatch to the correct type of transport implementation based on the form of the provided If you are seeing the error you posted, it is likely because of an issue with how you started the Here is an example if I run without wrapping in
You can see that when I run this output through |
@orirawlings , I tried your guide in a new linux machine, works well. but my git clone/pull operations are in a rest service, when a user want to clone a repo, curl my API, my service will clone the repo using ssh key. In my scenario, should I execute ssh-agent and ssh-add command before proceed my logic every time? Is there any other solution? |
If you want to provide explicit credentials you can use the |
If it helps, I did something like this to create the auth object needed to clone an ssh repo:
|
@orirawlings @wstrange , no lucky in my environment. @wstrange , I tried your code, still got error ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain |
That error message looks like it did use the key for authentication, but the authentication failed. Probably worth confirming that that git server the client is contacting has the correct ssh public key configured. |
@orirawlings @wstrange , it works. Thanks, I will close this issue |
I'm seeing If it matters, I'm on OS X not a Linux distro |
I have almost the same question but I need authorisation by user password and through ssh protocol: for example in my case:
|
This worked for me with ssh sshAuth, err := ssh.DefaultAuthBuilder("keymaster")
if err := r.Push(&git.PushOptions{Auth: sshAuth}); err != nil {
log.Error().Err(err).Msg("Push err")
os.Exit(1)
} Http Auth auth := &http.BasicAuth{Username: "user", Password: "pass",}
if err := r.Push(&git.PushOptions{Auth: auth}); err != nil {
log.Error().Err(err).Msg("Push err")
os.Exit(1)
} |
I'm summarised all types auth for clone private repo examples here |
This is how i work url := "git@github.com:supanadit/gostay.git"
var publicKey *ssh.PublicKeys
sshPath := os.Getenv("HOME") + "/.ssh/id_rsa"
sshKey, _ := ioutil.ReadFile(sshPath)
publicKey, keyError := ssh.NewPublicKeys("git", []byte(sshKey), "")
if keyError != nil {
fmt.Println(keyError)
}
_, err := git.PlainClone(url, false, &git.CloneOptions{
URL: urlGitConversion,
Progress: os.Stdout,
Auth: publicKey,
}) |
can you give me a sample about clone a private repo using ssh key? thanks
The text was updated successfully, but these errors were encountered: