How to Generate and Use SSH Keys (Ed25519) on Windows, macOS and Linux
Create an Ed25519 SSH key, protect it with a passphrase, load it into ssh-agent on Windows, macOS or Linux, and add it to GitHub or a server.
Table of contents
- How SSH keys work (in 60 seconds)
- Why Ed25519?
- Step 1: Check for existing keys
- Step 2: Generate a new Ed25519 key
- Step 3: Add the key to ssh-agent
- Step 4: Add your public key to GitHub (or GitLab, Bitbucket)
- Step 5: Use the key to log in to a server
- Managing multiple keys with ~/.ssh/config
- Troubleshooting common errors
- Security best practices
SSH keys let you log in to servers and push code to GitHub, GitLab or Bitbucket without typing a password — and they are far harder to steal or guess than passwords. This guide walks through creating a modern Ed25519 key, protecting it properly, and using it on Windows, macOS and Linux.
You will need a terminal and about ten minutes. Every command here uses OpenSSH, which ships with macOS, nearly all Linux distributions and current versions of Windows 10 and 11.
How SSH keys work (in 60 seconds)
An SSH key is a pair of files:
- Private key (
id_ed25519) — stays on your computer and must never be shared. - Public key (
id_ed25519.pub) — safe to share. You copy it to every server or service you want to access.
When you connect, the server uses your public key to challenge your computer, and your computer proves it holds the matching private key — without ever sending the private key over the network. That is why a leaked public key is harmless and a leaked private key is serious.
Why Ed25519?
ssh-keygen can create several key types. For new keys, Ed25519 is the sensible default: keys are small, signing is fast, and the algorithm is designed to avoid several implementation pitfalls of older schemes. GitHub's own documentation recommends it.
Only choose RSA if you must connect to a legacy system that doesn't support Ed25519; in that case, use at least 3072 bits (ssh-keygen -t rsa -b 4096).
Step 1: Check for existing keys
Before generating anything, see whether you already have a key.
macOS / Linux:
ls -al ~/.ssh
Windows (PowerShell):
Get-ChildItem $HOME\.ssh
If you see id_ed25519 and id_ed25519.pub, you already have a key. You can reuse it or create a new one with a different filename (see Step 2).
Step 2: Generate a new Ed25519 key
Run the same command on every operating system:
ssh-keygen -t ed25519 -C "you@example.com"
-t ed25519selects the key type.-Cadds a comment that helps you identify the key later. An email address orlaptop-2026both work.
You will be asked where to save the key. Press Enter to accept the default (~/.ssh/id_ed25519). If you want a separate key — for example, one for work — type a path such as ~/.ssh/id_ed25519_work.
Choose a strong passphrase
Next, ssh-keygen asks for a passphrase. Use one. A passphrase encrypts the private key file, so a stolen copy is useless without it. In Step 3 you will set up ssh-agent so you don't have to type it every time.
When finished, you'll see a fingerprint and a small "randomart" image. Your keys are now in ~/.ssh (or C:\Users\<you>\.ssh on Windows).
Have a hardware security key? If you own a FIDO2 key (such as a YubiKey) and your OpenSSH is version 8.2 or later, you can create a hardware-backed key with
ssh-keygen -t ed25519-sk. The private key material then never leaves the device. The same phishing-resistant principle powers passkeys — see our passkeys explainer.
Step 3: Add the key to ssh-agent
ssh-agent holds your unlocked key in memory so you enter the passphrase once per session instead of on every connection.
Linux
Most desktop environments start an agent automatically. If not:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
macOS
Start the agent and add the key, storing the passphrase in your macOS Keychain:
eval "$(ssh-agent -s)"
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Then create or edit ~/.ssh/config so the key loads automatically after restarts:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
(--apple-use-keychain replaced the older -K flag in recent macOS releases. If you get an error, your macOS may expect -K.)
Windows 10 and 11
Windows includes OpenSSH, but its agent service is disabled by default. Open PowerShell as Administrator and run:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
Then, in a normal (non-admin) PowerShell window:
ssh-add $HOME\.ssh\id_ed25519
The Windows agent stores the key securely and reloads it after reboots, so you only do this once.
Step 4: Add your public key to GitHub (or GitLab, Bitbucket)
Copy the public key to your clipboard:
# macOS
pbcopy < ~/.ssh/id_ed25519.pub
# Linux (X11, requires xclip)
xclip -selection clipboard < ~/.ssh/id_ed25519.pub
# Windows (PowerShell)
Get-Content $HOME\.ssh\id_ed25519.pub | Set-Clipboard
Or just print it with cat ~/.ssh/id_ed25519.pub and copy the single line that starts with ssh-ed25519.
On GitHub, go to Settings → SSH and GPG keys → New SSH key, give it a descriptive title (for example "Work laptop 2026"), paste the key and save. GitLab and Bitbucket have equivalent pages under your user settings.
Now test the connection:
ssh -T git@github.com
The first time, you'll be asked to confirm GitHub's host fingerprint. Compare it with the fingerprints published in GitHub's documentation before typing yes. A successful test greets you by username.
Finally, make sure your repositories use SSH remotes:
git remote -v
git remote set-url origin git@github.com:USERNAME/REPOSITORY.git
Step 5: Use the key to log in to a server
To access a Linux server, its ~/.ssh/authorized_keys file must contain your public key.
From macOS or Linux, the easiest method is:
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com
From Windows, which doesn't ship ssh-copy-id, append the key manually:
Get-Content $HOME\.ssh\id_ed25519.pub | ssh user@server.example.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Then connect with ssh user@server.example.com. Once key login works, consider disabling password authentication on the server (PasswordAuthentication no in /etc/ssh/sshd_config) — but only after confirming you can log in with your key, or you may lock yourself out.
Managing multiple keys with ~/.ssh/config
If you have separate keys for personal and work accounts, an SSH config file keeps them straight:
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yes
Host prod
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519
Now ssh prod connects to the server, and git clone git@github-work:company/repo.git uses your work key. IdentitiesOnly yes stops SSH from offering every key it knows about, which avoids "too many authentication failures" errors.
Troubleshooting common errors
"Permission denied (publickey)"
The server didn't accept any key you offered. Check that the public key is in the right account's authorized_keys (or on GitHub), and run ssh -v user@host to see which keys are being tried.
"WARNING: UNPROTECTED PRIVATE KEY FILE!" Your private key's permissions are too open. On macOS/Linux, fix them:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
On Windows, make sure only your user account has access to the file (Properties → Security).
"Could not open a connection to your authentication agent"
The agent isn't running in this shell. Run eval "$(ssh-agent -s)" on macOS/Linux, or start the ssh-agent service on Windows as shown in Step 3.
Asked for a passphrase every time
The key isn't loaded into the agent, or (on macOS) your ~/.ssh/config is missing UseKeychain yes and AddKeysToAgent yes.
Security best practices
- One key per device. If a laptop is lost, remove only that key from GitHub and your servers.
- Always use a passphrase, combined with an agent for convenience.
- Never copy your private key into cloud drives, chat messages or repositories.
- Audit regularly. Remove keys you no longer recognise from GitHub settings and from servers'
authorized_keysfiles. - Rotate after incidents. If a device may be compromised, generate new keys and revoke the old ones.
SSH keys protect the infrastructure behind your code — and that infrastructure is a real target. Our report on the actively exploited Puppet Server vulnerability shows why access to management systems needs to be tightly controlled.
Frequently asked questions
+Should I use Ed25519 or RSA for SSH keys?
Use Ed25519 unless you must connect to a very old system that doesn't support it. Ed25519 keys are short, fast and secure. If you need RSA for compatibility, use at least 3072 bits.
+Do I need a passphrase on my SSH key?
It is strongly recommended. Without a passphrase, anyone who copies your private key file can use it immediately. With ssh-agent you only type the passphrase once per session, so the inconvenience is small.
+Can I use the same SSH key on multiple computers?
You can, but it is better practice to create a separate key per device. If one laptop is lost or stolen, you revoke just that key without affecting the others.
+Where are SSH keys stored?
By default in the .ssh folder of your home directory: ~/.ssh on macOS and Linux, and C:\Users\<you>\.ssh on Windows. The private key is id_ed25519 and the public key is id_ed25519.pub.
Sources & references
- GitHub Docs — Generating a new SSH key and adding it to the ssh-agent
- GitHub Docs — Testing your SSH connection
- OpenBSD manual — ssh-keygen(1)
- OpenBSD manual — ssh_config(5)
- Microsoft Learn — Key-based authentication in OpenSSH for Windows
Spotted an error? See our Corrections Policy.
- #ssh
- #git
- #github
- #linux
- #windows
- #macos
- #security
The KernelBrief editorial desk researches, writes and fact-checks every article published on this site. Every article is checked against primary sources (official documentation, vendor announcements, standards bodies and original research) before publication. Every factual claim is linked to its source, and corrections are handled under our published Corrections Policy.
Related articles
Git Merge vs Rebase Explained: How Each Works, When to Use Them, With Examples
Git merge vs rebase: how each combines branches, when to use which, the golden rule of rebasing, and safe commands for pull, conflicts and force-push.
· 8 min read
F5 BIG-IP Buffer Overflow Flaws: Six Critical CVEs, Who Is Affected and How to Patch
F5 disclosed six critical BIG-IP stack buffer overflows (CVSS 9.8) that crash TMM without login. Affected versions, risky configs and hotfixes.
· 4 min read
VMware vCenter Zero-Day CVE-2026-123890 Was Exploited for Months: Who Is Affected and How to Patch
VMSA-2026-0009 fixes vCenter auth bypass CVE-2026-123890, exploited since September per Mandiant. Fixed builds, no workaround, and what to check.
· 6 min read