macOS ships with OpenSSH, so you don't need to install anything. Open Terminal and follow along.
#1. Generate the key
ssh-keygen -t ed25519 -C "you@example.com"-t ed25519picks the Ed25519 algorithm: modern, compact and fast.-Cadds 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.
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.comYou now have two files:
| File | What it is | Share it? |
|---|---|---|
~/.ssh/id_ed25519 | Private key | Never |
~/.ssh/id_ed25519.pub | Public key | Yes, 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:
ssh-add --apple-use-keychain ~/.ssh/id_ed25519Then tell SSH to use the Keychain automatically:
Host *
AddKeysToAgent yes
UseKeychain yesDetails and Linux-safe options: save your SSH passphrase in Keychain.
#3. Copy the public key
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:
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@server.example.com#5. Test it
ssh -T git@github.comHi 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:
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:
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.