Generate SSH keys on Windows with the built-in OpenSSH client. The right PowerShell command is ssh-keygen -t ed25519. The right way to use the agent is Start-Service ssh-agent then ssh-add. The team that has this set up has SSH that works from PowerShell, CMD, and VS Code without installing PuTTY or any third-party tool.
Table of contents
- The right PowerShell command
- Starting the ssh-agent
- Adding the key to a server
- The right ~/.ssh/config
- FAQ
The right PowerShell command
The right way to generate an SSH key on Windows:
ssh-keygen -t ed25519 -C "alice@workstation"
The command prompts for the file location and passphrase. The right answer is to use the default location ($env:USERPROFILE\.ssh\id_ed25519) and to set a passphrase.
Starting the ssh-agent
The right way to start the agent on Windows:
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
The right answer is to set the agent to start automatically. The wrong answer is to start it manually on every reboot.
Adding the key to a server
The right way is ssh-copy-id:
ssh-copy-id alice@server
If ssh-copy-id is not available, copy the public key manually with Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard and paste into the server’s authorized_keys.
The right ~/.ssh/config
The right way to configure the SSH client on Windows is ~/.ssh/config (the same format as on Linux). The right defaults:
Host *
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
FAQ
Does Windows ship with OpenSSH?
Yes, since Windows 10 1809 and Windows Server 2019. The right answer is to enable it in Settings → Apps → Optional features.
Why is the agent not running?
The right answer is to check Get-Service ssh-agent. If it is Stopped, run Start-Service ssh-agent.
Can I use PuTTY’s .ppk key?
Yes, but the right answer is to convert it to OpenSSH format with PuTTYgen.
What about WSL2?
The right answer is to use the native Windows OpenSSH for general SSH, and WSL2’s OpenSSH for Linux-specific scripts.
How do I add a key to GitHub?
The right answer is to copy the public key with Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | Set-Clipboard and paste into GitHub.
What if ssh-keygen is not found?
The right answer is to install OpenSSH Client: Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0.
Can I use Ed25519 on Windows?
Yes, since Windows 10 1809.
If you are sizing the infrastructure for the kind of project this post covers, the RunxBuild hosting calculator is the right place to model the line items. The compute, the memory, the storage, the bandwidth, the database - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual usage in one place.
Useful related references: