Skip to content

Instantly share code, notes, and snippets.

@ComFreek
Last active October 22, 2023 09:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ComFreek/b4bddf7f46d77222110731f3c9aecbba to your computer and use it in GitHub Desktop.
Save ComFreek/b4bddf7f46d77222110731f3c9aecbba to your computer and use it in GitHub Desktop.
Windows: Using SSH keys comfortably with Git, SVN, and remote servers

Windows: Using SSH keys comfortably with Git, SVN, and remote servers

also works for Git Bash and Cygwin users on Windows

  1. Be sure to have a recent version of Windows 10 (>= Windows 10 1809)

  2. Activate Microsoft's official OpenSSH feature

  3. Install

    • KeePass: a cross-platform password manager
    • KeeAgent: a plugin for KeePass allowing you store (encrypted) SSH keys in the database and expose them to software that needs it (e.g. Git, SVN). In more technical terms, KeeAgent exposes an SSH agent.

    If you use Chocolatey, the package manager for Windows, simply type: choco install -y keepass keepass-plugin-keeagent

  4. Configure KeeAgent to use OpenSSH: open KeePass, go to Tools -> Options -> KeeAgent and tick Enable agent for Windows OpenSSH (experimental)

    screenshot of ticking that option

  5. Configure Git to use OpenSSH: git config --global core.sshcommand "C:/Windows/System32/OpenSSH/ssh.exe"

  6. If you use SVN: set the environment variable SVN_SSH to C:/Windows/System32/OpenSSH/ssh.exe as well.

If you perform the latter two steps from within Git Bash (or Cygwin), you will be able to use your SSH keys from within there, too!

You are ready to go!

Usage

Caveat (as of 2020-11-19)

git push hangs when pushing repos with Git LFS contents. For them, I'd recommend resorting to the previous approach (which I used for years):

  • configure KeePass and KeeAgent as above

  • install Kitty, a maintained successor of Putty: choco install kitty

  • for every affected repo, do once:

    • copy your remote from git remote -v (e.g. git@gitlab.example.com:my_group/my_repo.git)
    • run C:/ProgramData/chocolatey/bin/PLINK.exe <your remote>, verify the host's fingerprint, and accept
    • git config core.sshcommand "C:/ProgramData/chocolatey/bin/PLINK.exe"
    • git push can now be run as usual

    The step with running PLINK.exe once manually is necessary because otherwise the confirmation question for the host's fingerprint will appear during git push, where you cannot answer it apparently (due to some terminal/shell boundary issues?).


Credits to Bratkartoffel (German forum) for suggesting to use KeeAgent.

ComFreek, reminder to self: if you change this Gist's URI, also change it in the two posts at https://www.tutorials.de/threads/ssh-keys-sinnvoll-unter-windows-git-bash-nutzen.405127/ that reference it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment