Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Last active April 4, 2026 04:20
Show Gist options
  • Select an option

  • Save yokawasa/39f7fe2eea0ec76000d67392c7df7967 to your computer and use it in GitHub Desktop.

Select an option

Save yokawasa/39f7fe2eea0ec76000d67392c7df7967 to your computer and use it in GitHub Desktop.
Use ssh-agent & macOS Keychain to skip manual SSH password input

If Entering Your SSH Password on macOS Is Annoying, Use macOS Keychain - ssh-add --apple-use-keychain

On macOS, integrating ssh-agent with macOS Keychain is the cleanest solution.


Why Using Only ssh-agent Is Not Enough

With ssh-agent, you can avoid entering your passphrase every time. If you do it manually, it looks like this:

# Start the agent (it is often already running)
eval "$(ssh-agent -s)"

# Add your key (you enter the passphrase once here)
ssh-add ~/.ssh/id_ed25519

However, this still becomes a hassle because you need to repeat steps in several situations:

  • It stops when your shell session ends.
  • You need to run it again every time you close the terminal, and the same applies after a reboot.

Use It Together with macOS Keychain

Method 1: Add Your Key to Keychain

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

Warning: The old ssh-add -K option is deprecated. Use --apple-use-keychain instead.

Method 2: Add Settings to ~/.ssh/config

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

That's it. Your key is automatically restored to ssh-agent when macOS starts, so once registered, no more repeated passphrase input is needed.

Keychain Security

Keychain is part of macOS security infrastructure and integrates with Touch ID and Secure Enclave. It does not store your passphrase as plain text, so you can maintain strong security while keeping day-to-day usability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment