Generate SSH RSA Key Pairs on Windows with WSL

Date Published: 20 January 2022

Generate SSH RSA Key Pairs on Windows with WSL

Secure Shell Protocol (SSH) keys provide an alternate way to authenticate with many services like GitHub. Creating them on Windows is simple using Windows Subsystem for Linux (WSL).

Windows Subsystem for Linux

First you'll need to have WSL running on your computer. Set up WSL for Windows.

Generate SSH RSA Key Pair

Open a WSL terminal (Start -> WSL -> Enter) and enter the following command:

ssh-keygen

It will ask you where to save the key - just hit enter and use the default (/home/username/.ssh/id_rsa).

Enter your passphrase (or just hit enter) and confirm it.

Your key files will be generated.

WSL Terminal showing commands

Find the Keys in Windows

The easiest way to find the keys on your Windows file system is to run explorer.exe . from the appropriate directory. As you can see in the image above, change directory to your home folder (/home/ssmith in my case). Then run explorer to launch File Explorer.

File Explorer Showing Files in Folder

Protect Your Private Key

The id_rsa file contains your private key. Keep it secure and don't share it with anyone.

The id_rsa.pub file is your public key. As such, you can share it with any app with which you wish to authenticate.

If you wish to use SSH with GitHub, start here.

Summary

It's easy to set up SSH keys on Windows using WSL and the ssh-keygen command. Refer to this article next time you need to do so. Thanks!

Steve Smith

About Ardalis

Software Architect

Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.