Git and libgit2

Git/Libgit2 Notes

Published 2023-05-10.
Time to read: 1 minutes.

This page is part of the 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:

Shell
$ git config core.sshCommand "ssh -i ~/.ssh/id_rsa"

The above causes the following to be added to .git/config:

.git/config
[core]
        sshCommand = ssh -i ~/.ssh/id_rsa

This is helpful for debugging ssh connectivity issues, for example by increasing ssh verbosity:

Shell
$ git config core.sshCommand "ssh -vi ~/.ssh/id_rsa"

SSH Agents

Both command line git and libgit2 use any ssh-agent that is running.

Shell
# 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


* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.