• About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings
Monday, November 2, 2026
  • Login
PacketNebula
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download
No Result
View All Result
PacketNebula
No Result
View All Result
Home Security

How to generate an SSH key (ssh-keygen)

by Stéphane Cardon
3 September 2026
in Security
0
Close-up of a metal door key on a keyring against a black background

Image: Pittigrilli / Wikimedia Commons, CC BY-SA 4.0

Share on FacebookShare on Twitter

Still typing a password every time you SSH into a box? One command ends that: ssh-keygen -t ed25519, then Enter to accept the default path and a passphrase when it asks. You get two files, a private key you guard and a matching .pub you can hand to any server. GitHub and GitLab take it too. ed25519 is the modern default in 2026; the only reason we fall back to RSA 4096 is an ancient server that hasn't heard of it yet. Same command in a Linux or macOS terminal and in PowerShell on Windows 10 and 11. We'll walk the two prompts and the easy way to get the public key onto a server. Plus the passphrase question most people get wrong.

The short answer

Run ssh-keygen -t ed25519 and take the default path. Set a passphrase when it asks. Keep the private key, share the .pub. Same command everywhere, and ssh-copy-id user@host installs the public key on a server for you.

ed25519the key type to use
2 filesprivate key + .pub
any OSLinux, macOS, Windows
Answer card showing ssh-keygen -t ed25519 generating a private key and a public .pub key.
One command, two files. You share the .pub and guard the other one.

Run ssh-keygen and answer the two prompts

Linux
ssh-keygen -t ed25519 -C "you@example.com"

The -C part is just a label baked into the key so you can tell it apart later. An email works, so does “laptop-2026”. On Windows, the identical command runs in PowerShell.

First it asks where to save the key: press Enter to accept ~/.ssh/id_ed25519, unless you’re juggling several keys and want a custom name. Then the passphrase. Set one. It encrypts the private key, so the file on its own is useless to whoever copies it. You type it once per session, that’s it.

Copy the public key, and the one case for RSA

The easy way, on Linux and macOS:

Linux
ssh-copy-id user@host

That appends your .pub to the server’s ~/.ssh/authorized_keys. No ssh-copy-id (Windows, mostly)? Print the public key and paste it into that file yourself:

Linux
cat ~/.ssh/id_ed25519.pub
Terminal showing ssh-keygen -t ed25519 creating the key pair, then cat printing the public key.
The whole thing end to end. The line starting ssh-ed25519 is what goes on the server.

Hit a server too old for ed25519? Make an RSA key instead, and go 4096 bits, never the old 2048 default:

Linux
ssh-keygen -t rsa -b 4096

The passphrase question

People skip the passphrase because typing it feels like friction. It isn’t. An agent caches it after the first use, so day to day you never notice it, and the payoff is that a leaked private key is just an encrypted blob. The only place I leave it empty is a throwaway automation key that nothing important trusts.

If the key is refused and you’re certain it’s the right one, check permissions before anything else. This is the single most common reason a perfectly good key fails, and the server logs it as a failed authentication rather than as the permission problem it actually is.

Linux and macOS
chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys

Your home directory matters too. If it’s group writable, sshd refuses the key on principle, because anyone in that group could have rewritten your authorized_keys. Strict mode is on by default and it’s right to be. When you’re still stuck, ssh -vvv user@host prints exactly which keys it offered and what the server said about each, and the answer is usually in there within twenty lines.

Frequently asked questions

Which key type should I use, ed25519 or RSA?

ed25519, no contest. It's fast and the keys are tiny, with security that holds up. The only reason we still generate an RSA key with "ssh-keygen -t rsa -b 4096" is an old server or device that doesn't support ed25519 yet.

Should I set a passphrase on my SSH key?

Yes. The passphrase encrypts the private key on disk, so a stolen laptop doesn't hand over your servers with it. You type it once per session and an SSH agent remembers it after that. The one exception we'd accept is an unattended automation key, and even that one deserves a second thought.

How do I copy my public key to a server?

On Linux and macOS, "ssh-copy-id user@host" does it in one step. Anywhere else, append the contents of id_ed25519.pub to ~/.ssh/authorized_keys on the server. The private key (the file without .pub) never leaves your machine. Never copy that one.

Where are the key files saved?

In the .ssh folder of your home directory: id_ed25519 (private) and id_ed25519.pub (public). That's ~/.ssh on Linux and macOS, C:Usersyou.ssh on Windows. The .pub is the only file you ever share.

Tags: guidesecurityssh
ShareTweet
Previous Post

How to kill the process using a port on Linux

Next Post

How to extract and create tar.gz archives (tar)

Stéphane Cardon

Stéphane Cardon

Network cybersecurity engineer: architecture, LAN and WLAN, system administration. He runs PacketNebula, where he publishes the tools and answers he wanted for his own work.

Next Post
Four magnetic tape data cartridges: Sony LTO Ultrium 3, Exabyte 8mm, TDK DDS-3 and a Verbatim data cassette

How to extract and create tar.gz archives (tar)

Free tools

  • IPv4 subnet calculator
  • DNS lookup
  • SSL certificate checker
  • HTTP headers checker
  • SPF, DKIM and DMARC checker
  • JWT decoder
  • Cron expression builder
  • Chmod calculator
  • Password generator

All 24 tools →

Guides to keep handy

  • Flush the DNS cache on Windows
  • Kill the process using a port
  • Generate an SSH key
  • Secure a new Ubuntu VPS
  • Find files on Linux
  • Extract and create tar.gz

More guides →

Who writes this

Stéphane Cardon, network cybersecurity engineer. Architecture, LAN and WLAN, system administration. PacketNebula holds the tools and answers he wanted for his own work.

About this site →

  • About
  • Editorial policy
  • Contact
  • Privacy
  • Legal
  • Cookie settings

Copyright © 2026 Stephane Cardon.

No Result
View All Result
  • Home
  • News
  • Tools
    • Network
    • Security
    • Developer
    • Sysadmin
    • SEO
    • Email & DNS
  • Guides
  • Trackers
    • LLM API pricing
    • Open-weight models
    • Retirements calendar
    • Infrastructure deals
  • About
  • Download

Copyright © 2026 Stephane Cardon.

Cookies, your call

We use Google Analytics to see which pages get read. Once our AdSense application is approved, articles and guides will carry Google ads. Nothing runs until you say yes, and nothing runs on the tool pages. Details