Git and libgit2
Mike Slinn

Git/Libgit2 Notes

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

This page is part of the git collection, categorized under git, ssh.

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:

        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)