How to automatically load SSH keys on Windows autostart using Pageant

How to automatically load SSH keys on Windows autostart using Pageant
Photo by FLY:D / Unsplash

In this article I will show you how to load your private SSH key automatically when you start your Windows computer. To do this, we use PuTTY to create a SSH key-pair and Pageant to load the private key on start-up.

💡
If you have already installed Pageant and have an SSH key-pair, you can jump directly to Shortcut Creation.

Prerequisites

  • Working Windows installation

Pageant Installation

We will install Pageant using the PuTTy installation package. You can download the Windows installer from here. For this tutorial I will use the 64-bit x86 installer.

When the download is complete, start the installation by double-clicking on the msi installer file. We will install PuTTy in the default folder C:\Program Files\PuTTY:

Just follow the installation process. It should be fairly self-explanatory. If the installation is successful, you should find pageant.exe, putty.exe, puttygen.exe and many other files in the C:\Program Files\PuTTY directory. If this is the case, you can proceed with creating your SSH key-pair.

Creating your SSH key-pair

To create the SSH key-pair, we use PuTTYgen. After opening PuTTYgen, press Generate and move the mouse over the empty area:

After completion, your new public SSH key will be displayed. Be sure to enter a key passphrase and also confirm the passphrase in the second field.

Now you can save the key-pair with the two buttons Save public key and Save private key. With this key-pair, you can now use Pageant and PuTTY to access SSH endpoints. In the next step we will create a shortcut to open Pageant automatically when Windows starts.

Shortcut Creation

First we need to create the initial shortcut. To do this, simply right-click on the desktop. In the pop-up, select New and then Shortcut.

Now you need to enter the path to the pageant.exe. If you have followed these installation instructions, you can find the file at:

C:\Program Files\PuTTY\pageant.exe

Before you click Next, you have to append the path to your private SSH key. For this to work, you must enclose the pageant.exe-path in double quotes. After that, simply append the path to your private SSH key. Don't forget to enclose this path in double quotes as well. You can even add multiple SSH keys this way:

"C:\Program Files\PuTTY\pageant.exe" "C:\path\to\key1.ppk" "C:\path\to\key2.ppk"

The shortcut should now look something like this:

Press Next, enter a name for the shortcut and save it. You can now test the shortcut to see if it successfully loads your private SSH key by double-clicking on it.

Add shortcut to autostart

Every Windows user has their own startup folder, which can be found here:

C:\Users\$USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Or even a bit shorter:

%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup

Move the shortcut to your personal startup folder and you are ready to go.

With this setup, you no longer have to worry about forgetting to start Pageant or adding your SSH keys manually. Just enter your key password on start-up and never think about it again while you work.