Skip to content

Instantly share code, notes, and snippets.

@ahacke
Last active March 13, 2023 07:05
Show Gist options
  • Save ahacke/68de1c823d2612fa575cb462f656882a to your computer and use it in GitHub Desktop.
Save ahacke/68de1c823d2612fa575cb462f656882a to your computer and use it in GitHub Desktop.
Guide on how to setup github ssh keys with keepass

Github SSH with KeePass

Requirements

  • Git
  • Github Account
  • KeePass with KeeAgent
  • Putty Package
    • plink
    • puttygen
  • ssh-keygen

Installation

Setup

Generate SSH Keys

  1. Start puttygen.exe
  2. Configure number of bits. Github can handle 4096 bits.
  3. Click on Generate and move the mouse
  4. Go to Conversions->Export OpenSSH and export your private key
    1. A password can be set, but keep in mind that the password must be entered every time the key is used
  5. Copy your private key to ~/.ssh/id_rsa.
  6. Create the RFC 4716 version of the public key using ssh-keygen
    1. ssh-keygen -e -f ~/.ssh/id_rsa > ~/.ssh/id_rsa_RFC4716.pub
  7. Convert the RFC 4716 version of the public key to the OpenSSH format:
    1. ssh-keygen -i -f ~/.ssh/id_rsa_RFC4716.pub > ~/.ssh/id_rsa.pub
  8. Copy the string from the public key field at the top, which starts with "ssh-rsa ..."

Set SSH Key in Github

  1. Move to https://github.com/settings/keys
  2. Create a new key
  3. Provide a name
  4. Paste the string from the public key field of puttygen
  5. Save it

Configure KeePass & KeeAgent

  1. Create a new or open a database
  2. Create a new entry for your github.com account
  3. Select the tab Advanced
    1. Click on Attach
    2. Select the previously saved public and private key generated by puttygen
  4. Select the tab KeeAgent
    1. Check Allow KeeAgent to use this entry
    2. Select the private key in the Attachement area of the Private Key File Location
    3. For further details about KeeAgent, click here
  5. Save the entry

You can check if the key is loaded by opening the KeeAgent window via Tools -> KeeAgent. If the key is not loaded yet, load it this time manually by right clicking on the entry and selecting Load SSH Key. The ssh key should be loaded and visible in the KeeAgent window now.

Plink for Git

Set a global environment variable GIT_SSH to tell git to use plink. GIT_SSH must point to the full windows path of plink.exe, i.e. “C:\Program Files (x86)\putty\plink.exe”

Checkout a Repository with SSH

  1. Start KeePass and open the database where the ssh key is stored
  2. Look for a SSH address of a git repository to clone, e.g. take this one.
  3. git clone <ssh_repository_address>
    1. If it is the first time accessing github.com like this, it may be necessary to "trust" this host and confirm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment