Generating SSH keys on Windows, Mac, and Linux

NicolasBrondinBernard

Author
@NicolasBrondinBernard

You don't know how to create an SSH key pair (public and private), let me explain how to do it!

Article published on 15/11/2021, last updated on 10/08/2026

SSH keys are cryptographic elements used to encrypt and decrypt communications between two remote machines through the Secure SHell protocol.

Each set is always made up of two distinct keys: the public key and the private key, so we commonly refer to it as a "key pair."

Why create an SSH key pair

In the case of a client and a server, the server is given the public key, and the client keeps the private key.

This way, even if the public key is intercepted, the information encoded with it cannot be decoded, because that requires the private key.

Most hosting providers (VPS, dedicated servers, etc.), as well as other online services, ask users to provide their keys in order to authenticate during the SSH connection.

Generate an SSH key pair with PuTTYgen

PuTTY is an SSH client that allows you to connect to a remote machine, through a fairly simple graphical interface. The advantage of PuTTY is that it is open-source and even though it was created for Windows, it is also available on Linux and MacOS.

But the second advantage of this software is that it comes with a small suite of utilities, including PuTTYgen.

As its name suggests, PuTTYgen will let you generate SSH key pairs very easily! Let's see how to do it.

Install Putty and PuTTYgen

For MacOS, you just need to go through HomeBrew (more information here):

brew install putty

For Linux, you can use APT with compatible distributions (more information here):

apt-get install putty putty-tools

And on Windows, all you need to do is go to the official website: https://www.putty.org/, download and run the provided installer.

Create a key pair

The first step is to launch puttygen(.exe), which is located in the same folder as the Putty executable. You should see the interface below appear:

Next, all you need to do is click the "Generate" button and move your mouse in the white area labeled "Key" to generate the random data the software needs to create the SSH key.

By moving your mouse, you are generating entropy. If you're not familiar with the concept of randomness in computing, read my article on the subject.

At the end of the process, you should see the public key appear in the box as shown below:

If you want to protect your private key with a password (recommended), you'll then need to fill in the "Key passphrase" and "Confirm passphrase" fields.

All that's left is to click the "Save public key" and "Save private key" buttons to save the key pair in two separate files!

Alternative: Generate an SSH key pair directly in the terminal

If you're on Linux, Mac, or using a Unix-compatible terminal on Windows, you can use a utility that's already available, called ssh-keygen.

To generate a key pair, simply run the following command:

ssh-keygen

Then answer the questions asked by the tool (file, password, etc.) and you can generate an SSH key in no time, without installing anything!


Chunli Ju sur Unsplash

Finished reading this article?
Our newsletter

No spam. Only free content, news, and ever more resources to level up your skills!

Join +1500 developers

Comments (0)

to leave a comment

No comments yet