Generate SSH Keys on Any System

How to generate SSH keys on Linux, macOS, and Windows.

·2 min read
Contents

This guide covers generating SSH keys on all major operating systems.

Linux

OpenSSH is pre-installed on most Linux distributions.

bash
# generate an Ed25519 key (recommended)
ssh-keygen -t ed25519

# or RSA if Ed25519 is not supported
ssh-keygen -t rsa -b 4096

If ssh-keygen is not available, install it:

bash
# Debian/Ubuntu
sudo apt install openssh-client

# Fedora/RHEL
sudo dnf install openssh-clients

macOS

macOS includes OpenSSH out of the box. Open Terminal and run:

bash
ssh-keygen -t ed25519

Your keys will be saved to ~/.ssh/id_ed25519 (private) and ~/.ssh/id_ed25519.pub (public).

To add the key to the macOS keychain so you don't have to enter your passphrase every time:

bash
ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Windows

Option 1: Built-in OpenSSH (Windows 10/11)

Windows 10 (1809+) and Windows 11 include OpenSSH. Open PowerShell or Command Prompt:

powershell
ssh-keygen -t ed25519

Keys are saved to C:\Users\<username>\.ssh\.

Option 2: PuTTY (puttygen)

If you need a .ppk key for PuTTY:

  1. Download PuTTY and open PuTTYgen
  2. Select EdDSA (Ed25519) or RSA (4096 bits) as the key type
  3. Click Generate and move your mouse to create randomness
  4. Save the private key as a .ppk file

To generate a PuTTY key from the command line (if PuTTY tools are installed):

bash
puttygen -t ed25519 -o my_key.ppk

Option 3: Git Bash / WSL

If you have Git for Windows or WSL installed, you can use ssh-keygen the same way as on Linux:

bash
ssh-keygen -t ed25519

Verifying your key

After generating, you can view your public key:

bash
cat ~/.ssh/id_ed25519.pub

This is what you'll add to servers, GitHub, GitLab, etc.

Keep reading