Tag Archives: SSH

Using SSH keys with GitHub / BitBucket / Azure DevOps on Windows

Couldn’t get this to work, but now it does, so… time for another “note to self”. 🙂

Prerequisites

  • Git, obviously…
  • PuTTY, with puttygen, plink and pageant, to be exact…

Setup

  1. Open puttygen.

  2. Either Load an existing private key, or Generate a new one.

  3. Copy the public key (“Public key for pasting …”) and add it to the git provider settings:

    • https://github.com/settings/keys
    • https://bitbucket.org/account/user/[username]/ssh-keys/
    • https://dev.azure.com/[organization]/_usersSettings/keys
  4. Open pageant.

  5. Load your private key.

  6. Check that the key authentication works with plink:

    plink -v git@github.com
    plink -v git@bitbucket.org
    plink -v git@ssh.dev.azure.com
  7. Set the GIT_SSH environment variable to C:\Program Files\PuTTY\plink.exe.

    ^^ This is the detail that so many StackOverflow answers and blog/forum posts didn’t mention. Without this, plink worked fine, but git commands still failed with authentication errors.

  8. (optional) Add a shortcut to the private key file to your startup folder. This way pageant will be automatically started, with your key, ready to go, whenever Windows boots up.

    start shell:startup

Usage

Now, as long as pageant is running with your private key loaded, it should work to clone, pull, push, etc., both to and from, both private and public git repositories. E.g. like this:

git clone git@github.com:example/some-private-repo.git

Note: If you’re asked to accept/store/cache a key, but pressing y doesn’t work, connect using putty first, which should give you a dialog with the same question which does work. Putty will complain/crash because there’s not actually an ssh shell to connect to, but that’s fine. After the key has been saved by putty, git should work fine. E.g. like this:

putty -ssh git@github.com

Sources: makandracards.com, vladmihalcea.com

External tool definitions for mRemoteNG

Here are some external tool definitions I have defined in mRemoteNG.

WinSCP

Display name

WinSCP (sftp)

Filename

C:\Program Files (x86)\WinSCP\WinSCP.exe

Arguments

sftp://%username%:%password%@%hostname%:%port%/

Ping

Display name

Ping

Filename

cmd

Arguments

/c ping -t %HostName%

Traceroute

Display name

Ping

Filename

cmd

Arguments

/c set /P = | tracert %HostName%

More can be found at the mRemoteNG forum.

If you haven’t tried mRemoteNG, you should. It’s very handy if you’re on Windows and need to connect to various servers through for example SSH and RDP. Sure beats plain PuTTY at least…