Published 2023-05-10.
Time to read: 1 minutes.
git
collection.
Libssh2 vs ssh
Libgit2
does not using the system ssh
command.
Instead, it is statically linked to libssh2
,
which does not read .ssh/config
,
so libgit2
does not support that either.
In contrast, command line git
uses the ssh
command,
and therefore supports .ssh/config
.
Specifiying an SSH Key
Git can be configured to use a specific ssh
key for authorization of a given repo.
Within the repo, type:
$ git config core.sshCommand "ssh -i ~/.ssh/id_rsa"
The above causes the following to be added to .git/config
:
[core]
sshCommand = ssh -i ~/.ssh/id_rsa
This is helpful for debugging ssh connectivity issues, for example by increasing ssh
verbosity:
$ git config core.sshCommand "ssh -vi ~/.ssh/id_rsa"
SSH Agents
Both command line git
and libgit2
use any
ssh-agent
that is running.
# Launch ssh-agent; best to do this in ~/.bashrc $ eval $(ssh-agent) > /dev/null
$ ssh-add Identity added: /home/mslinn/.ssh/id_rsa (/home/mslinn/.ssh/id_rsa)
$ ssh-add -l 1024 SHA256:Xdv1AE4QTd0NfrwOGVTamF/wxnvFufCtsOIoOXtX5Mw /home/mslinn/.ssh/id_rsa (RSA) $ echo $SSH_AGENT_PID 2196