GuidesSecurity

ssh-keygen: generate an SSH key for a server and GitHub

ssh-keygen -t ed25519 step by step: passphrase and ssh-agent on Linux, macOS and Windows, ssh-copy-id, GitHub, a separate key for an agent, hardware keys.

December 2, 2026The Everpod team
The short answer

Run ssh-keygen -t ed25519 -C "a label", press Enter to accept ~/.ssh/id_ed25519, and type a passphrase. That makes two files: the private key, which never leaves the machine, and id_ed25519.pub, the line you give to a server or to GitHub. Ed25519 has been the default since OpenSSH 9.5, so plain ssh-keygen makes the same key; use -t rsa -b 4096 only for a system that refuses Ed25519. Put the public key on a server with ssh-copy-id -i ~/.ssh/id_ed25519.pub you@your-server. For a coding agent on that server, make a separate key there instead of copying yours. The current release is OpenSSH 10.6p2 (November 5, 2026).

One command, and what each part does

ssh-keygen -t ed25519 -C "laptop 2026-12" -f ~/.ssh/id_ed25519
Copied

It asks for a passphrase twice and writes ~/.ssh/id_ed25519 and ~/.ssh/id_ed25519.pub. Leave off -f and it asks for the file name instead, offering the same default. Give a second key a name of its own with -f: writing a new key over an old one replaces the old private key, and every server and account that trusted it stops letting you in.

FlagWhat it doesWhen to use it
-t ed25519
The key typeOptional since OpenSSH 9.5 (October 2023), when Ed25519 became the default; spelling it out costs nothing on an older machine
-C "..."
The comment at the end of the public keyAlways: it is the only thing that tells you, in a server’s authorized_keys or a list of keys, which machine this line belongs to. Without it the comment is user@host. GitHub’s example uses an email address; a machine name and date work better when you later have to remove one
-f path
Where the private key goes; the public key gets .pub addedFor any key that is not your main one
-b bits
Key sizeRSA only (default 3072, minimum 1024). Ed25519 has a fixed length and ignores it
-N ""
Sets the passphrase without askingOnly to make a key with no passphrase on purpose. A real passphrase typed after -N ends up in your shell history; let the prompt ask
-a rounds
How many rounds protect the passphrase in the fileRarely; OpenSSH 10.6 raised the default from 24 to 32

Three more are worth knowing once the key exists. ssh-keygen -p -f ~/.ssh/id_ed25519 adds, changes or removes the passphrase without making a new key. ssh-keygen -lf ~/.ssh/id_ed25519.pub prints the key’s fingerprint, the short form a server or GitHub shows when it lists keys. And ssh-keygen -y -f ~/.ssh/id_ed25519 prints the public key again from the private one, if you deleted the .pub file.

Which type to pick

The ssh-keygen manual lists six types as of OpenSSH 10.6:

TypeUse it for
ed25519
Everything, unless something below applies. Short keys, the default, and accepted by GitHub
rsa
Old systems and appliances that reject Ed25519. GitHub’s key guide gives ssh-keygen -t rsa -b 4096 for “a legacy system that doesn't support the Ed25519 algorithm”
ecdsa
Policies that require a NIST curve; -b picks 256, 384 or 521
ed25519-sk, ecdsa-sk
A key that lives on a hardware security key (below)
mldsa44-ed25519
A post-quantum hybrid, enabled in OpenSSH 10.6 on October 6, 2026. Both ends must run software that knows it; GitHub’s key docs do not mention it as of December 2026

DSA is gone: OpenSSH 10.0 removed it, and GitHub no longer accepts new DSA keys. Anyone who tried the experimental post-quantum keys before 10.6 has to make new ones, because the 10.6 release notes say keys from the earlier implementation “must be regenerated and/or removed.” ssh -V shows which OpenSSH a machine has.

A passphrase you type once per session

The passphrase encrypts the private key file, so a copied file is useless without it. The manual is blunt that “There is no way to recover a lost passphrase”; a forgotten one means a new key. To avoid typing it on every connection, hand the unlocked key to ssh-agent, which holds it in memory.

Linux. Start an agent in the current shell and add the key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
Copied

Adding AddKeysToAgent yes to ~/.ssh/config makes ssh add the key the first time you unlock it; the ssh_config manual gives no as the default, and a time interval in place of yes makes the agent forget it after that long.

macOS. Apple’s OpenSSH can keep the passphrase in the macOS Keychain. GitHub’s block for ~/.ssh/config is:

Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519
Copied

Repeat the same three lines under a Host line for your server to get the same there. Then store the passphrase once:

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

UseKeychain is Apple’s addition and is not in OpenSSH’s own manual. An ssh that does not know the option, such as one installed separately from Apple’s, stops with “Bad configuration option: usekeychain”, and GitHub’s fix is an IgnoreUnknown UseKeychain line above it. GitHub also says to leave the UseKeychain line out for a key with no passphrase.

Windows. ssh-keygen is part of the OpenSSH Client feature and runs in PowerShell or Command Prompt; Microsoft’s key management page says “If you don't specify an algorithm, Ed25519 is used.” Press Enter at the file prompt to save under C:\Users\you\.ssh. If the command is not found, check for the feature and add it from an administrator PowerShell:

Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
Copied

Microsoft notes the ssh-agent service is disabled by default. Enable it from an administrator PowerShell (the first two lines), then add the key from your ordinary one:

Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
Copied

GitHub’s version of the same step sets the service to Manual rather than Automatic; Automatic starts it again after every restart. Microsoft describes the Windows agent as storing keys “within a Windows security context that's associated with your Windows account.”

Putting the public key on a server

On macOS and Linux, ssh-copy-id logs in once with whatever works today (usually the server’s password) and appends the key to ~/.ssh/authorized_keys, creating the folder and file if needed:

ssh-copy-id -i ~/.ssh/id_ed25519.pub you@your-server
Copied

Keep the -i. Its manual says that without it, it first checks whether ssh-add -L lists anything “and if so those keys are used”, so a laptop whose agent holds a work key, a GitHub key and a client’s key installs all of them on the new server. -n prints what it would install without doing it, and -p gives a port other than 22.

By hand, from a session already on the server (a provider’s web console, or a password login), as the user you will log in as:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Copied

Paste the whole .pub line, which starts with ssh-ed25519 and ends with your comment, on one line of its own. The permissions are not decoration: the sshd manual says that if the file, ~/.ssh or the home directory is writable by other users, sshd “will not allow it to be used”, and the key is ignored.

From Windows to a Linux server there is no ssh-copy-id. Microsoft’s own example writes to a Windows server’s paths; for Linux, pipe the key through ssh and let the server’s shell do the same four steps:

Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | ssh you@your-server 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys'
Copied

Then open a second terminal and log in with ssh you@your-server; it should ask for your key’s passphrase, or nothing if the agent holds it, never the server password. ssh -v shows which key files it offered when it does not. Once a key login works, turning password logins off is the next step, and disabling SSH password login safely covers the order that avoids locking yourself out. The first connection to a new server also asks you to accept the server’s own key, which is a different thing from yours; what SSH is explains both halves.

Adding it to GitHub

On github.com, Settings → SSH and GPG keys → New SSH key, give it a title, leave the type as Authentication, and paste the .pub line (pbcopy < ~/.ssh/id_ed25519.pub copies it on a Mac, Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub | clip on Windows). With the GitHub CLI signed in, the same from a terminal, then a test:

gh ssh-key add ~/.ssh/id_ed25519.pub --type authentication --title "laptop 2026-12"
ssh -T git@github.com
Copied

A working key answers “Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access.” The first time, SSH asks you to confirm GitHub’s host key; GitHub’s testing page gives its Ed25519 fingerprint as SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU, and that is what to compare against before typing yes. The type you chose when adding it, Authentication or Signing, decides whether the key logs you in or signs commits. An organisation that uses SAML single sign-on also needs the key authorized for it before it opens that organisation’s repositories.

A key for the coding agent on the server

A key on your GitHub account stands in for your username and token, so it can do to repositories whatever you can. Copying that private key to a server where Claude Code, Codex or another agent runs gives the agent all of it, along with anything that can steer the agent, such as instructions planted in a README. So the agent gets a key of its own, made on the server so the private half never travels:

ssh-keygen -t ed25519 -f ~/.ssh/agent_myrepo -C "agent on your-server: myrepo" -N ""
cat ~/.ssh/agent_myrepo.pub
Copied

Run it as the Linux user the agent runs as. This key has no passphrase on purpose, because nobody is there to type one when the agent pushes at three in the morning; what limits it is where you attach it. Added to one repository as a deploy key, it reaches that repository alone, read-only unless you tick write access. With several repositories, each needs its own key and an SSH host alias, and a fine-grained token is often simpler; GitHub access for a coding agent’s server compares the options and sets up the aliases.

Agent forwarding (ssh -A, or ForwardAgent yes) looks like a way around this and is not. The ssh manual warns that anyone on the remote host who can get past the permissions on the agent’s socket “can access the local agent through the forwarded connection”, and that while it cannot copy the keys out, it can use the ones the agent holds to authenticate. The manual does not name coding agents, but the inference is direct: the socket belongs to your user on that server, so a coding agent running as that user needs to bypass nothing, and while you are connected it can sign in as you with every key your laptop’s agent holds.

A hardware security key

With a FIDO2 key such as a YubiKey plugged in, the private key is made on the device and cannot be copied off it; using it needs a touch:

ssh-keygen -t ed25519-sk -O resident -O verify-required -C "security key"
Copied

-O resident stores the key handle on the device, so ssh-keygen -K can write the key files on a new computer (into the current folder); -O verify-required asks for the device’s PIN or fingerprint each time, not just a touch. Leave both off for a plain touch-to-use key. If the command fails with “invalid format” or “feature not supported”, GitHub’s guide gives -t ecdsa-sk as the fallback. A touch only a person can give is the point, and it rules this type out for the agent’s own key on a server; it suits the key on your laptop that opens the server.

A server that was rebuilt keeps your key working only if its new authorized_keys has your line again, and SSH on your side will then warn that the server’s own key changed; that warning has its own fix.

Give your AI agents a permanent cloud computer.

We set it up and secure it, so all you do is use them. Run Claude Code, Codex or any agent you use, more at once than your laptop can hold, and keep them working when it’s closed. Or have OpenClaw set up and run for you.

See the developer pod

From $24/mo · your own plan or API key

Get your OpenClaw agent

$29/mo, cancel anytime · model usage included