Skip to content

Latest commit

 

History

History
56 lines (48 loc) · 2.48 KB

20221129.org

File metadata and controls

56 lines (48 loc) · 2.48 KB

Let Git for Windows use Pageant as SSH agent

If you want Git for Windows to use Pageant as an SSH agent, you have to set environment variable GIT_SSH to the path of the Plink executable. Here,

  • GIT_SSH “is a program that is invoked instead of ssh when Git tries to connect to an SSH host”[fn:1], and
  • Plink is a Windows command-line tool to establish an SSH connection and comes with the Putty suite of tools.

So Git for Windows will use Plink to connect to the repo server and Plink will query a running Pageant instance for the SSH key-pair.

When you use Git to establish an SSH connection to a repo server for the first time, you’re asked to confirm the fingerprint of that server. This works fine from the command-line but can be a problem when you use Git from another tool. One example of such a tool is the Git porcelain lazygit. lazygit doesn’t give you access to Plink and you’re stuck.

The easiest way around that is to clone the Git repo from the command-line, where you will have access to Plink:

C:\Users\Pieter\repos> git clone [email protected]:swinkels/yadm-dotfiles.git
 The host key is not cached for this server:
  github.com (port 22)
You have no guarantee that the server is the computer you
think it is.
The server's ssh-ed25519 key fingerprint is:
  ssh-ed25519 255 <fingerprint>
If you trust this host, enter "y" to add the key to Plink's
cache and carry on connecting.
If you want to carry on connecting just once, without adding
the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n, Return cancels connection, i for more info) y
Using username "git".
Access granted. Press Return to begin session.
Server refused to allocate pty

C:\Users\Pieter\repos>

Another approach is to use Plink directly, for example via

plink -agent [email protected]

This creates an SSH connection to github.org as user git using the SSH key pair in Pageant.

Finally, Plink stores the fingerprint in the Windows registry for any subsequent connections, the exact location being Computer\HKEY_CURRENT_USER\SOFTWARE\SimonTatham\PuTTY\SshHostKeys. If you delete a fingerprint here, you will have to trust its host again.

[fn:1] The quote is from section Git-Internals - Environment Variables of the Pro Git book.