question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue cloning repository over SSH

See original GitHub issue

Reproduction steps

I have a bug when I try to clone repository over SSH key.

What I did?

public static string passphrase = "123";
public static string sshDir = "C:\\Users\\HereIsMyUserName\\Desktop\\keys\\.ssh";

CloneOptions options = new CloneOptions
        {
            Checkout = false,
            CredentialsProvider = (url, user, cred) => new SshUserKeyCredentials()
            {
                PrivateKey = sshDir + "id_rsa",
                Passphrase = passphrase,
                PublicKey = sshDir + "id_rsa.pub",
                Username = "git"
            }
        };

        public string CreateUniqueTempDirectory()
        {
            var uniqueTempDir = Path.GetFullPath(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
            Directory.CreateDirectory(uniqueTempDir);
            return uniqueTempDir;
        }


        private void button1_Click(object sender, EventArgs e) 
        {
            try
            {
                Repository.Clone(sshURL, CreateUniqueTempDirectory(), options);
            }
            catch (Exception)
            {

                throw;
            }
            
        }

What I get?

I get exception:

System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

at LibGit2Sharp.Core.NativeMethods.git_clone(git_repository*& repo, String origin_url, FilePath workdir_path, GitCloneOptions& opts) at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts) in C:\Users\DVasilje\Downloads\libgit2sharp-ssh-master\libgit2sharp-ssh-master\LibGit2Sharp\Core\Proxy.cs:line 356 at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options) in C:\Users\DVasilje\Downloads\libgit2sharp-ssh-master\libgit2sharp-ssh-master\LibGit2Sharp\Repository.cs:line 732 at libgit2sharpSSHtest.Form1.button1_Click(Object sender, EventArgs e) in C:\VS2019\sshtest\libgit2sharpSSHtest\libgit2sharpSSHtest\Form1.cs:line 51 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm)

###How did I created my SSH key?

$ ssh-keygen -t rsa -C “your_email@example.com” inside gitBash, like GitHub recommended it

Version of LibGit2Sharp

(both 1.0.22 of LibGit2Sharp-SSH and LibGit@Sharp-SSH-updated-libssh2 version 1.0.25 )

Operating system(s) tested; .NET runtime tested

Windows 10, .NET 4.7.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
KokoShanercommented, Dec 13, 2021

I don’t know why the status is still open, @ethomson clearly stated that libgit2 developers are not implementing nor will in future implement SSH, and therefore we should do it on our own. Sadge

0reactions
raveslavecommented, Dec 13, 2021

whats the status of this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to set up SSH and Clone Repository using SSH in Git?
Open Git Bash and navigate to the directory in which you want to clone the repository.
Read more >
A quick GitHub SSH clone example
To clone GitHub with SSH keys, just open Windows PowerShell or an Ubuntu terminal and issue the Git clone command and specify the...
Read more >
Git clone fails when cloning via SSH
Git clones fail when using ssh even if an Access key has been added to the repository or an SSH key has been...
Read more >
git clone through ssh
So at this point you can clone the repository to any machine simply by running git clone <user>@<server>:<relative_path><your_project>.git . (As ...
Read more >
Unable to clone repository using ssh #46057
When I try to clone a test repository, I get a Permission denied. See below for the log. ... git@github.com: Permission denied (publickey)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found