Authentication failed using SshUserKeyCredentials in libgit2sharp-SSH

Some authentication issues with SshUserKeyCredentials with libgit2sharp-SSH:

var co = new CloneOptions();
co.CredentialsProvider = (_url, _user, _cred) => new SshUserKeyCredentials { PrivateKey="C:\\path\\to\\private_key" };
Repository.Clone("git@... .repository.git", path, co);

I found that the SshUserKeyCredentials object is scanning the source code, so my first question would be if I could use this object to deploy a key based check from gitlab?

It seems that the object wants any combination of PrivateKey, Username, PublicKey and Passphrase. I am currently using PrivateKey.

The error I end up with is:

{"Failed to start SSH session: Unable to exchange encryption keys"}

If this method should not work, is there an alternative way to use deployment keys to programmatically control git from a C # environment?

+4
source share
1

-.

  • null ; string.Empty.

  • .

  • PEM ( PuttyGen = > Export OpenSSH openssl rsa -in id_rsa -out id_rsa.pem).

  • , , base64, ( , PuttyGen, , ),

    ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAoblahblahblahblahblah

git, Bitbucket. , , null, do string.Empty.

:

CredentialsHandler handler = (_url, _user, _cred) => new SshUserKeyCredentials
                    {
                        PrivateKey = @"C:\Users\blah\.ssh\keys\bitbucket.pem",
                        Username = "git",
                        Passphrase = string.Empty,
                        PublicKey = @"C:\Users\blah\.ssh\keys\bitbucket.pub"
                    }

. : PHP ssh2_auth_pubkey_file(): : , base64

+1

Source: https://habr.com/ru/post/1665114/


All Articles