This guide covers generating SSH keys on all major operating systems.
Linux
OpenSSH is pre-installed on most Linux distributions.
# generate an Ed25519 key (recommended)
ssh-keygen -t ed25519
# or RSA if Ed25519 is not supported
ssh-keygen -t rsa -b 4096If ssh-keygen is not available, install it:
# Debian/Ubuntu
sudo apt install openssh-client
# Fedora/RHEL
sudo dnf install openssh-clientsmacOS
macOS includes OpenSSH out of the box. Open Terminal and run:
ssh-keygen -t ed25519Your 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:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519Windows
Option 1: Built-in OpenSSH (Windows 10/11)
Windows 10 (1809+) and Windows 11 include OpenSSH. Open PowerShell or Command Prompt:
ssh-keygen -t ed25519Keys are saved to C:\Users\<username>\.ssh\.
Option 2: PuTTY (puttygen)
If you need a .ppk key for PuTTY:
- Download PuTTY and open PuTTYgen
- Select EdDSA (Ed25519) or RSA (4096 bits) as the key type
- Click Generate and move your mouse to create randomness
- Save the private key as a
.ppkfile
To generate a PuTTY key from the command line (if PuTTY tools are installed):
puttygen -t ed25519 -o my_key.ppkOption 3: Git Bash / WSL
If you have Git for Windows or WSL installed, you can use ssh-keygen the same way as on Linux:
ssh-keygen -t ed25519Verifying your key
After generating, you can view your public key:
cat ~/.ssh/id_ed25519.pubThis is what you'll add to servers, GitHub, GitLab, etc.
Keep reading
Control Root Login Using SSH
How to disable password-based root login by replacing it with SSH key-based login.
SSH key: Permissions 0660 for '~/.ssh/id_rsa' are too open.
How to fix the 'Permissions 0660 for '~/.ssh/id_rsa' are too open' error when trying to login to your remote host using an SSH key
