brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: ssh-add --apple-use-keychain stores your SSH key passphrase in the macOS keychain

macOS
~/tips/tip-macos-ssh-add-apple-use-keychain

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

Saves an SSH key passphrase in the macOS keychain, so it is not asked again.

A passphrase on an SSH key is a good habit, and typing it again after every restart gets old fast. The Mac keychain can remember it for me.

Apple’s version of ssh-add has two extra options. The first adds the key and also stores its passphrase in your keychain:

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

The man page says that when you remove identities with -d, the passphrase is removed from the keychain too. After a restart the agent is empty again, and the second option loads the keys back using the stored passphrases:

ssh-add --apple-load-keychain

To make ssh do this by itself, put it in ~/.ssh/config:

Host *
  AddKeysToAgent yes
  UseKeychain yes

UseKeychain is the macOS option that searches the keychain for the passphrase when a key is used, and stores the passphrase after it has been verified. The default is no. AddKeysToAgent yes adds a key to the running agent when it is loaded from a file.

The caveats come from the man pages. UseKeychain is incompatible with PKCS11Provider. The older flags -K and -A were renamed to --apple-use-keychain and --apple-load-keychain, so a guide that still uses them may behave differently, and with -S, SSH_SK_PROVIDER or APPLE_SSH_ADD_BEHAVIOR set to openssh you get standard OpenSSH behavior instead.

It is also a trade of security for comfort: anyone who gets into your unlocked Mac account can use the key without typing the passphrase.

Further reading: ssh-add man page, ssh_config man page

More macOS tips System Settings > Accessibility > Hover Text > When using the pointer A Smart Folder in Notes collects notes by tag, checklist or date Type # in a Mac note to tag it, then filter by tag in the sidebar tmutil isexcluded ~/Projects/app/node_modules Crop an image in Preview by dragging a frame and clicking Crop All macOS tips (99) All topics

Link