Network security

How to Generate an SSH Key: Ed25519 on Mac, Windows and Linux

One ssh-keygen command creates a modern Ed25519 key pair. Here is the exact command, how to protect it with a passphrase, and how to use it with GitHub and servers.

Cysoro Security TeamPublished · 10 min read
$ ssh-keygen -ted25519Generating public/private key pair. id_ed25519 NETWORK SECURITY GenerateSSH key One command. No more passwords.
Quick answer

Generate an SSH key by running ssh-keygen -t ed25519 -C [email protected] in a terminal, pressing Enter to accept the default location, and choosing a strong passphrase. This creates a private key in ~/.ssh/id_ed25519 and a public key in ~/.ssh/id_ed25519.pub. Add the private key to ssh-agent with ssh-add, then copy the public key to GitHub or a server with ssh-copy-id.

Key takeaways

  • Use Ed25519 for new keys; fall back to RSA with 4096 bits only on legacy systems that do not support it.
  • Always set a passphrase, keep the private key private, and store it with permissions only you can read.
  • Copy only the .pub file to servers and GitHub, then test with ssh -T [email protected] before relying on the key.

Passwords are easy to phish and easy to guess. An SSH key is a pair of cryptographic files that lets you log in to servers and GitHub without typing a password at all, and it takes about a minute to create.

What is an SSH key?

An SSH key is a pair of related cryptographic files: a private key that stays on your computer and a public key that you can share freely. The server checks that your private key matches the public key it holds, and lets you in without a password.

SSH, or Secure Shell, is the protocol used to log in to remote servers and to push code to GitHub over SSH. When you generate a key, your computer creates both files at once, usually in the ~/.ssh folder. The private file is named id_ed25519 and the public file is the same name plus .pub.

Think of the public key as a padlock and the private key as the only key that opens it. You can hand the padlock to any server, but if anyone else gets your private key, they can pretend to be you. That is why the private key must never be shared, emailed, or committed to a repository.

What do you need before you generate an SSH key?

You need a terminal and an SSH client, which are already installed on macOS and Linux, and included with Git Bash or Windows Terminal on Windows. No account or download is required to generate the key itself.

First, check whether you already have a key, so you do not overwrite one you use. GitHub's documentation recommends listing the ~/.ssh folder first. Run ls -al ~/.ssh on macOS or Linux, or the same command in Git Bash on Windows, and look for files named id_ed25519 or id_rsa.

If a key already exists and works, you do not need a new one. If you need a separate key for a different service, give the new key a custom filename when ssh-keygen asks where to save it, instead of overwriting the existing file.

One key pair, two very different jobs Your laptopPrivate key: id_ed25519Never share it.Keep it secret. Server or GitHubPublic key: id_ed25519.pubSafe to share.Share it freely. ssh-keygen creates both The server proves you hold the private key — without ever seeing it.
Private key stays with you; public key goes to the server. Illustration by Cysoro.

How do you generate an SSH key?

Run ssh-keygen -t ed25519 -C "[email protected]" in your terminal, press Enter to accept the default file location, then type a strong passphrase twice. The whole process takes under a minute.

GitHub's SSH key documentation gives exactly this command as the standard way to generate a new key, replacing the email with your own. The -t ed25519 flag picks the Ed25519 algorithm, and the -C flag adds a comment, usually your email, so you can tell keys apart later.

When ssh-keygen asks where to save the key, press Enter to accept the default, which is /home/YOU/.ssh/id_ed25519 on Linux, /Users/YOU/.ssh/id_ed25519 on macOS, or /c/Users/YOU/.ssh/id_ed25519 in Git Bash on Windows. If that file already exists, ssh-keygen will ask whether to overwrite it; say no and choose a different filename instead.

Next it asks for a passphrase. Type a strong one, and type it again to confirm. A passphrase encrypts the private key on disk, so even if someone copies the file, they still cannot use it without the passphrase. Generate a strong one with our password generator if you need a starting point.

You can press Enter for no passphrase, but that is only safe on a machine nobody else can reach, and it is not recommended for keys that access production servers or GitHub.

Ed25519 vs RSA: which key type should you choose?

Choose Ed25519 for new keys. It is faster, shorter, and secure with a 256-bit key, and it is the default GitHub recommends. Use RSA only when a legacy system does not support Ed25519.

Ed25519 keys are small: the public key is a single short line, and the private key file is compact. RSA keys need 4096 bits to reach a comparable security level, which makes them longer and slower. Most modern servers, GitHub, GitLab, and cloud providers support Ed25519.

Key typeCommandKey sizeUse it when
Ed25519ssh-keygen -t ed25519256-bitDefault for all new keys
RSA 4096ssh-keygen -t rsa -b 40964,096-bitLegacy system without Ed25519 support
ECDSAssh-keygen -t ecdsa -b 521521-bitSpecific compliance or hardware needs
DSADo not use—GitHub dropped DSA support on 15 March 2022

GitHub improved security by dropping older, insecure key types on 15 March 2022. As of that date, DSA keys are no longer supported, and RSA keys generated after 2 November 2021 must use a SHA-2 signature algorithm. If you still have an old DSA or 1024-bit RSA key, generate a fresh Ed25519 key and retire the old one.

You can also add -a 100 to increase the number of key-derivation rounds used to protect the passphrase, for example ssh-keygen -t ed25519 -a 100 -C "[email protected]". It makes unlocking the key slightly slower, and makes guessing the passphrase harder if the private key file is stolen.

How do you generate an SSH key on Mac, Windows and Linux?

The command is the same on all three systems; only the terminal you open is different. On macOS open Terminal, on Linux open your terminal, and on Windows open Git Bash or Windows Terminal with OpenSSH installed.

On macOS, run the ssh-keygen command, then add the key to the ssh-agent and store the passphrase in the Keychain with ssh-add --apple-use-keychain ~/.ssh/id_ed25519. GitHub's macOS guidance also recommends adding AddKeysToAgent yes, UseKeychain yes and IdentityFile ~/.ssh/id_ed25519 to your ~/.ssh/config file, so the key loads automatically.

On Windows, use Git Bash, which ships with OpenSSH and ssh-keygen. The same command works, and the key lands in C:\Users\YOU\.ssh\id_ed25519. You can add it with ssh-add c:/Users/YOU/.ssh/id_ed25519. Windows 10 and 11 also include OpenSSH in PowerShell, so ssh-keygen works there too, with the same prompts.

On Linux, the command works in any terminal, and the key lands in ~/.ssh/id_ed25519. Start the agent with eval "$(ssh-agent -s)" if it is not already running, then run ssh-add ~/.ssh/id_ed25519.

Generate a key in four steps 1Run ssh-keygenssh-keygen -t ed25519-C "[email protected]" 2Accept locationPress Enter for~/.ssh/id_ed25519 3Set passphraseStrong, unique,typed twice 4Add to agentssh-add~/.ssh/id_ed25519 Then copy only the .pub file to GitHub or your server.
The four steps to generate and load an SSH key. Illustration by Cysoro.

How do you add your SSH key to ssh-agent?

Start ssh-agent, then run ssh-add ~/.ssh/id_ed25519 and type your passphrase once. The agent keeps the unlocked key in memory, so you do not have to type the passphrase for every connection.

On Linux and macOS, start the agent with eval "$(ssh-agent -s)" if it is not running, then add the key. On macOS, use ssh-add --apple-use-keychain ~/.ssh/id_ed25519 to store the passphrase in the Keychain. On Windows in Git Bash, the same ssh-add command works with the Windows path to the key.

Check that the key loaded with ssh-add -l, which lists the fingerprints of keys the agent holds. If the list is empty, the agent is running but no key was added, or you added a different filename. If you created the key with a custom name, replace id_ed25519 in the command with that name.

For a hardware security key, GitHub documents a separate flow: generate the key with ssh-keygen -t ed25519-sk while the security key is plugged in. The private key then lives on the hardware device, and you must touch it to authenticate.

How do you copy your public key to a server or GitHub?

Copy only the public key, never the private key. For a server, use ssh-copy-id user@server; for GitHub, paste the .pub contents into Settings, then SSH and GPG keys, then New SSH key.

To see your public key, run cat ~/.ssh/id_ed25519.pub on macOS or Linux, or open the .pub file in a text editor on Windows. On macOS you can copy it straight to the clipboard with pbcopy < ~/.ssh/id_ed25519.pub, and on Windows with clip < ~/.ssh/id_ed25519.pub in Git Bash. The public key is one line starting with ssh-ed25519 and ending with your comment.

For a Linux server, ssh-copy-id appends that line to ~/.ssh/authorized_keys on the server and sets the right permissions. If ssh-copy-id is not available, copy the line manually into that file, then make sure the file is readable only by you. Test the connection with ssh user@server; you should be asked for the key passphrase, not the server password.

For GitHub, paste the public key into the key field, give it a title such as "MacBook Pro 2026", and save it. Test it with ssh -T [email protected]. A successful test replies with your username, even though the message says shell access is not provided.

How do you keep an SSH key secure?

Keep the private key private, protect it with a passphrase, and set its permissions so only you can read it. A key with loose permissions is a key anyone on a shared machine can copy.

On macOS and Linux, the .ssh folder should be mode 700 and the private key should be mode 600. Run chmod 700 ~/.ssh and chmod 600 ~/.ssh/id_ed25519 to fix them. SSH will refuse to use a private key that other users can read, and will warn you about it.

Never commit a private key to Git, never paste one into a chat, ticket, or AI tool, and never email it to yourself. If a private key is ever exposed, treat it as compromised: generate a new key, add the new public key everywhere the old one was used, and delete the old public key from servers and GitHub.

Use a different key per device, not one key copied across laptops. That way, losing one laptop means revoking one key, not every key you own. And back up the private key only in an encrypted form, such as in a password manager that supports secure notes, never as a plain file in cloud storage.

Why is my SSH key not working?

Most SSH key failures come from four causes: the public key was never added to the server, the permissions are wrong, the wrong key is being offered, or the passphrase was mistyped. Work through them in that order.

  • Permission denied (publickey). The server does not have your public key, or it is in the wrong file. Check ~/.ssh/authorized_keys on the server.
  • Bad permissions warning. Fix the private key with chmod 600 ~/.ssh/id_ed25519 and the folder with chmod 700 ~/.ssh.
  • Wrong key offered. Run ssh -v user@server and read which key files SSH tries; add the right one with ssh-add.
  • Agent has no identities. Run ssh-add -l; if it is empty, add the key again.
  • GitHub says the key is already in use. A public key can only be attached to one GitHub account, so generate a separate key for the second account.
  • Passphrase not accepted. Check caps lock and keyboard layout, then change the passphrase with ssh-keygen -p -f ~/.ssh/id_ed25519.

To see the fingerprint of a key, run ssh-keygen -lf ~/.ssh/id_ed25519.pub. Compare that fingerprint with the one shown by GitHub or your server when you connect, to confirm you are using the key you think you are using.

When should you replace an SSH key?

Replace a key when it is exposed, when the device holding it is lost or sold, when you leave a job, or when it uses an old algorithm such as DSA or short RSA. You do not need to rotate a healthy Ed25519 key on a fixed schedule, but you should review your keys at least once a year.

To rotate, generate a new key with a different filename, add the new public key to every server and service, test it, and only then remove the old public key. Doing it in that order means you are never locked out. Keep a list of where each key is installed, because an old key left on a forgotten server is a quiet back door.

For teams, this is a good moment to check the basics on your own network too. Our guide to how to secure your Wi-Fi covers the router settings that protect the network your keys travel over.

The bottom line

Generating an SSH key is one command, one passphrase, and one copy of the public key to each service you use. Ed25519 is the right default, a passphrase is not optional for keys that matter, and the private key never leaves your machine.

Generate the key, add it to ssh-agent, paste the .pub file into GitHub or your server, and test it before you disable password login. If you want to check the strength of the passphrase you chose, run it through our password strength checker.

Frequently asked questions

How do I generate an SSH key?

Run ssh-keygen -t ed25519 -C [email protected] in a terminal, press Enter to accept the default location, and choose a strong passphrase. This creates a private key in ~/.ssh/id_ed25519 and a public key in ~/.ssh/id_ed25519.pub.

What is the difference between Ed25519 and RSA keys?

Ed25519 is the modern default: faster, shorter, and secure with a 256-bit key. RSA needs 4096 bits for comparable security. Use RSA only on legacy systems that do not support Ed25519.

Where is my SSH key stored?

On Linux and macOS it is stored in ~/.ssh/, with the private key named id_ed25519 and the public key named id_ed25519.pub. On Windows with Git Bash it is in C:\Users\YOU\.ssh\.

Should I use a passphrase for my SSH key?

Yes, for any key that accesses production servers or GitHub. A passphrase encrypts the private key on disk, so a stolen key file is useless without it. Use ssh-agent so you only type the passphrase once per session.

How do I add my SSH key to GitHub?

Copy the contents of ~/.ssh/id_ed25519.pub, then in GitHub go to Settings, SSH and GPG keys, and click New SSH key. Paste the public key, give it a title, save it, and test with ssh -T [email protected].

Can I use the same SSH key on multiple computers?

You can, but you should not. Use a different key per device, so losing one laptop means revoking one key, not every key you own. Generate a fresh key on each new device.

Sources

  1. GitHub Docs — Generating a new SSH key and adding it to the ssh-agent
  2. OpenSSH — ssh-keygen manual
  3. NIST — SP 800-63B Digital Identity Guidelines
  4. GitHub Docs — Checking for existing SSH keys
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against GitHub's SSH documentation and the OpenSSH ssh-keygen manual.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free