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 with SSH - GitHub and BitBucket

See original GitHub issue

System information

  • node version: v10.14.1
  • npm version: 6.4.1
  • OS/version/architecture: Windows 10
  • Applicable nodegit version: 0.23.0

I am able to run the unit test for ssh clone:

it("can clone with ssh while manually loading an encrypted key", function() {
    var test = this;
    var url = "git@github.com:nodegit/test.git";
    var opts = {
      fetchOpts: {
        callbacks: {
          certificateCheck: function() {
            return 1;
          },
          credentials: function(url, userName) {
            return NodeGit.Cred.sshKeyNew(
              userName,
              sshEncryptedPublicKeyPath,
              sshEncryptedPrivateKeyPath,
              "test-password"
            );
          }
        }
      }
    };

    return Clone(url, clonePath, opts).then(function(repo) {
      assert.ok(repo instanceof Repository);
      test.repository = repo;
    });
  });

However, when I attempt using any new SSH key I generate either in Bitbucket or Github, I am getting the following error: Failed to authenticate SSH session: Unable to send userauth-publickey request

Is there any guidance on what I may have done wrong?

Here is my code:

const cloneURL: string = "git@github.com:repo/project.git";

let publickey: string = "path/to/pubKey";
let privatekey: string = "path/to/privKey";
let passphrase: string = "testpw";
let localPath: string = "path/to/repo";

var opts = {
  fetchOpts: {
    callbacks: {
      certificateCheck: function() {
        return 1;
      },
      credentials: function(url, userName) {
        return nodegit.Cred.sshKeyNew(
          userName,
          publickey,
          privatekey,
          passphrase
        );
      }
    }
  }
};

nodegit.Clone.clone(cloneURL, localPath, opts).then(function(repo) {
  if(repo instanceof nodegit.Repository) {
    console.log("Good!");
  }
  else {
    console.log("Bad!");
  }
}).catch((reason) => {
  console.log(reason);
});

Is this a patch issue or maybe how I am generating my key?? It works fine with regular git clone (I am supplying GIT_SSH_COMMAND in order to point to the right key location).

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
tychedeliacommented, Feb 27, 2019

Moved credentials outside of options as suggested by @ambrosejed, however, now getting:

node(46523,0x70000acc4000) malloc: *** error for object 0x1058039d0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Node v11.10.0

nodegit 0.23.1

0reactions
cavasinfcommented, Nov 21, 2019

Got the same problem here, solved by checking my ‘private key’ : Wrong format.

You need to export your private key to OpenSSH key image

Should look like this : https://github.com/nodegit/nodegit/blob/master/test/encrypted_rsa

And the code used is that one :

const Git = require('nodegit');

const cloneURL = "git@URL:PATH_TO_GIT.git";
var local_publickey = local("/ssh/ssh-public-manual.pub");
var local_privatekey = local("/ssh/openssh-private-key");
var tmpGitPath = "./tmp";

var opts = {
    fetchOpts: {
        callbacks: {
            certificateCheck: () => 0,
            credentials: function(url, userName) {
                return Git.Cred.sshKeyNew(
                    userName,
                    local_publickey,
                    local_privatekey,
                    "SECRET_OF_PRIVATE_KEY"
                );
            }
        }
    }
};

Git.Clone.clone(cloneURL,tmpGitPath,opts)
    .then(function(repo) {
        if(repo instanceof Git.Repository) {
            console.log("Good!");
        } else {
            console.log("Bad!");
        }
        console.log('Cloning DONE');
    })
    .catch(function(err) {
        console.log('/!\\ ERROR /!\\');
        console.log(err);
    });

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting SSH issues | Bitbucket Cloud Cloud KB
Bitbucket Cloud complains "Network is down" and cannot operate commands via ssh · Invalid SSH Key · Multiple SSH Keys settings for different ......
Read more >
Add SSH key for both github and bitbucket in single PC
Complete Guide to Add SSH keys for both github and bitbucket in single PC. if you already have one ssh key then you...
Read more >
Setting up a seperate Github and Bitbucket account
Git is set up for a single github user using https, not ssh; There is only a known_hosts file in ~/.ssh/ ... Obviously...
Read more >
Unable to deploy from Bitbucket using SSH Key #606 - GitHub
If this works, we know that the problem is something with your specific case perhaps the fact that you have a custom port....
Read more >
Open PR doesn't work with BitBucket and custom SSH ...
Describe the bug BitBucket allows to use a different SSH username than the traditional git (i.e. my-username@bitbucket.org instead of ...
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