I'm trying to use ssh-key authentication for performing push and pull command. Here is my function that pushes a new branch up to a remote:
var Q = require('q');
var NodeGit = require("nodegit");
exports.pushChangesToRemote = function (repo, branchName, remoteName) {
return NodeGit.Remote.lookup(repo, remoteName).then(function (remote) {
return remote.push(["{0}:{1}".format(branchName, branchName)], {
callbacks: {
credentials: function (url, userName) {
return NodeGit.Cred.sshKeyFromAgent(userName);
}
}
});
});
};
And I'm getting the error:
Error: error authenticating: no auth sock variable
When trying to push a new branch to 'origin'. Here is the output for running "#ssh-agent":
SSH_AUTH_SOCK=/tmp/ssh-2QVgJbbB5VHH/agent.4003; export SSH_AUTH_SOCK;
SSH_AGENT_PID=4004; export SSH_AGENT_PID;
echo Agent pid 4004;
How do I get the authentication to work? My ssh-key in stored in '~/.ssh/id_rsa' . And I notice that each time I push a branch in command line "git push origin
NVM.. figured it out. Just setting the ssh-key paraphrase to empty does the job.
@calvinhmw can you please elaborate?
@calvinhmw please study how ssh-agent works, its output needs to be swallowed by the current shell.
@saper Can you please elaborate? I have my key added to the agent, I use a keychain that makes the agent available systemwide, I can connect to git using the terminal, but I still get this error on a program that uses NodeGit.
➜ ~ printenv|grep SSH_AUTH_SOCK
SSH_AUTH_SOCK=/tmp/ssh-u5ebex8TtoEW/agent.2406
➜ ~ ssh-add -l
4096 SHA256:686c9+V65VoF7K/XXXX+XXXX [email protected] (RSA)
➜ ~ ssh -T [email protected]
Hi Luc45! You've successfully authenticated, but GitHub does not provide shell access.
Edit: This error is coming from libssh2, a NodeGit dependency:
path = agent->identity_agent_path;
if(!path) {
path = getenv("SSH_AUTH_SOCK");
if(!path)
return _libssh2_error(agent->session, LIBSSH2_ERROR_BAD_USE,
"no auth sock variable");
}
https://github.com/libssh2/libssh2/blob/master/src/agent.c#L157
For some reason, it can't parse the SSH_AUTH_SOCK environment variable. I will try to make this env var globally available in my Linux, I'll update here if I succeed.
For some reason, it can't parse the
SSH_AUTH_SOCKenvironment variable. I will try to make this env var globally available in my Linux, I'll update here if I succeed.
This is not about parsing, the variable is simply not there. Setting it in one terminal session or shell does not make it available in all sessions you might be using.
Personally I have
eval `/usr/local/bin/ssh-agent -s`
in my ${HOME}/.xinitrc file since I start X session manually with the startx command, so the agent is available to all programs and sessions under that X session.