// ssh keys

How to generate an SSH key on a Mac (Ed25519)

Five minutes, one command, and a key that's small, fast and secure. Here's the modern way to create an SSH key on macOS, plus the steps people usually skip.

Updated · 2 min read · by Pixel Worship, LLC

macOS ships with OpenSSH, so you don't need to install anything. Open Terminal and follow along.

#1. Generate the key

Terminal
ssh-keygen -t ed25519 -C "you@example.com"
  • -t ed25519 picks the Ed25519 algorithm: modern, compact and fast.
  • -C adds a comment (usually your email) so you can tell keys apart later.

SSH asks where to save it. Press Return to accept ~/.ssh/id_ed25519, or type a name such as ~/.ssh/id_ed25519_work if you're making a second key. Then enter a passphrase twice.

Output
Your identification has been saved in /Users/you/.ssh/id_ed25519
Your public key has been saved in /Users/you/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:Zp7Lm2Qx9Ws4Rt1Yv8Nb3Hc6Jk0Uf5Ge2Da7Ti9Oq1 you@example.com

You now have two files:

FileWhat it isShare it?
~/.ssh/id_ed25519Private keyNever
~/.ssh/id_ed25519.pubPublic keyYes, this is what servers and GitHub need

Need RSA for an old server? Use ssh-keygen -t rsa -b 4096 -C "you@example.com". Otherwise stick with Ed25519.

#2. Remember the passphrase in Keychain

Add the key to the agent and store its passphrase in the macOS Keychain:

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

Then tell SSH to use the Keychain automatically:

~/.ssh/config
Host *
  AddKeysToAgent yes
  UseKeychain yes

Details and Linux-safe options: save your SSH passphrase in Keychain.

#3. Copy the public key

Terminal
pbcopy < ~/.ssh/id_ed25519.pub

#4. Add it where you want to log in

GitHub: Settings → SSH and GPG keys → New SSH key → paste. (GitLab and Bitbucket have the same option under your profile settings.)

A server you can already reach:

Terminal
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com

#5. Test it

Terminal
ssh -T git@github.com
Output
Hi you! You've successfully authenticated, but GitHub does not provide shell access.

If you get Permission denied (publickey) instead, follow the Permission denied troubleshooting guide.

#6. Tell SSH which hosts use this key

With more than one key, pin each to its hosts so SSH doesn't guess:

~/.ssh/config
Host github.com
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

#Check your permissions

SSH refuses private keys that other users can read. ssh-keygen creates them correctly, but files copied from elsewhere often aren't:

Terminal
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519

#Do it in one sheet

EasySSHConfig's New Key sheet does all of this at once. Pick Ed25519, RSA or ECDSA, name the key, add a passphrase, tick "Remember in Keychain", and type the hosts it should be used for. It runs Apple's own ssh-keygen (the passphrase never appears on a command line), copies the public key for you, and writes the host rules.

Frequently asked questions

Ed25519 or RSA?

Use Ed25519. It's the modern default: short keys, fast, and secure. Use RSA (3072 or 4096 bits) only for old servers or devices that don't support Ed25519.

Do I need a passphrase?

It's optional but recommended: without one, anyone who copies your ~/.ssh folder can use the key. On a Mac you can store the passphrase in Keychain so you aren't asked again.

Where are SSH keys stored on a Mac?

In the hidden folder ~/.ssh in your home directory. The private key (for example id_ed25519) must stay secret; the .pub file is the public key you share.

How do I copy my public key on macOS?

Run pbcopy < ~/.ssh/id_ed25519.pub. That puts the public key on your clipboard, ready to paste into GitHub, GitLab or a server.