KitBench

Practical Mac, terminal, and digital workflow guides tested on real hardware.

Tested Mac and terminal guides.

3–5 minutes

SSH key hardening with Ed25519, passphrases, and macOS Keychain integration

Replace legacy RSA keys with Ed25519, raise key-derivation rounds with -a 100, tighten ~/.ssh permissions, and integrate Apple Keychain cleanly on macOS.

KitBench guide cover for SSH key hardening with Ed25519 on macOS

Sources are linked in this article. Found an error? Report a correction.

If ~/.ssh still holds an older RSA key with no passphrase, switching to Ed25519 with a strong passphrase and 100 key-derivation rounds (-a 100) takes three minutes. It removes legacy SHA-1 compatibility warnings and protects your private key file if a laptop or backup disk is exposed. On macOS, combining UseKeychain yes with IdentitiesOnly yes keeps passphrase protection active without prompting you on every Git push.

Every flag below was verified with OpenSSH 10.5p1 on Apple Silicon macOS 27.2.1.

How modern SSH key types compare

Key typePublic key sizeSecurity and supportRecommendation
ed2551968 charactersModern elliptic-curve cryptography; fast and avoids RSA padding pitfalls.Default choice for GitHub, GitLab, Linux servers, and macOS.
ed25519-skHardware-backedPrivate key stays on a FIDO2 USB key (e.g., YubiKey) and requires a touch.Best for production servers and sensitive repositories.
rsa (4096-bit, SHA-2)~720 charactersWorks on older appliances that lack Ed25519 support.Use only when a legacy server rejects Ed25519.
dsa or rsa (1024 to 2048-bit)DeprecatedDisabled by default in current OpenSSH.Retire and replace.

Step 1: Audit existing keys and file permissions

Inspect what sits inside ~/.ssh and ensure no other local user can read your private keys or configuration:

ls -la ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_* ~/.ssh/config 2>/dev/null
chmod 644 ~/.ssh/*.pub ~/.ssh/known_hosts 2>/dev/null

Step 2: Generate an Ed25519 key with 100 KDF rounds

The -a 100 option increases the bcrypt key-derivation rounds encrypting your private key file on disk, slowing offline guessing if someone copies the file:

ssh-keygen -t ed25519 -a 100 -C "macbook-2026" -f ~/.ssh/id_ed25519_primary

Set a unique 4-to-6-word random passphrase (50+ bits of entropy). You can test passphrase entropy locally in your browser with our Passphrase and Password Entropy Checker.

Step 3: Configure macOS Keychain and safer client defaults

Place global defaults at the bottom of ~/.ssh/config (keep host-specific overrides above Host *, since OpenSSH applies the first matching setting):

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentitiesOnly yes
  ForwardAgent no
  HashKnownHosts yes
  ServerAliveInterval 60
  ServerAliveCountMax 3

Store the passphrase in macOS Keychain once and confirm the key loaded:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519_primary
ssh-add -l

Keep ForwardAgent no as your default. Turning on global agent forwarding allows a root user on a compromised remote host to reuse your local agent socket to authenticate to other servers. When you need to hop through a bastion host, use ProxyJump bastion-host instead so your private key stays strictly on your Mac.

Step 4: Rotate out old keys without locking yourself out

Leave your old key active until the new one is tested. Add id_ed25519_primary.pub to GitHub, GitLab, or your server’s ~/.ssh/authorized_keys, verify a fresh login in a second terminal window while keeping the first session open, and only then remove the old public key line remotely.

If you use separate personal and work keys on one Mac, follow our guide to managing multiple GitHub accounts with SSH config, and check workstation-wide protections in our macOS privacy and security checklist.

Verify which key OpenSSH offers and troubleshoot permission errors

When a remote server rejects a new Ed25519 key, run a single verbose test connection rather than guessing which config block matched:

# Inspect effective SSH config for a target host without opening a session
ssh -G github.com | grep -E "^(hostname|user|identityfile|identitiesonly|forwardagent)"

# Trace the exact key negotiation during login
ssh -vvv -T git@github.com 2>&1 | grep -E "Offering public key|Server accepts key|Authentications that can continue"

Three errors show up most often after hardening ~/.ssh:

  • UNPROTECTED PRIVATE KEY FILE! means the private key is readable by group or other users. Fix it with chmod 600 ~/.ssh/id_ed25519_primary and chmod 700 ~/.ssh.
  • Too many authentication failures happens when ssh-agent holds five or more keys and IdentitiesOnly yes is missing. Adding IdentitiesOnly yes forces OpenSSH to try only the specific IdentityFile listed for that host.
  • Bad configuration option: usekeychain appears if you copy a macOS ~/.ssh/config to a Linux server. Wrap Apple-specific options with IgnoreUnknown UseKeychain above UseKeychain yes so the same config stays portable across macOS and Linux.

Treat every private key file under ~/.ssh as device-specific rather than copying the same private key across three laptops. Generating one Ed25519 key per machine takes ten seconds, and if one laptop is lost or retired, you revoke a single public key line in GitHub or authorized_keys without rotating credentials on your remaining devices. Keep only the public key fingerprint inventory in your notes so you can identify which Mac each authorized key belongs to months later.

Sources and verification

Stay in the loop

Get tested Mac, terminal, and workflow guides when new tutorials publish. Unsubscribe anytime.

Comments

Questions, corrections, and useful counterpoints are welcome. Keep comments specific and on topic.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.