0

I've installed OpenSSH from Homebrew, because I need a newer version to support hardware keys (Big Sur comes with 8.1; 8.2+ is needed).

However, my system insists on persisting the default ssh-agent stored in /usr/bin rather than the one in /opt/homebrew/bin/ssh-agent. I can manually change over to the Homebrew agent with eval (ssh-agent -c), but this isn't persisted across new terminal sessions.

In case it matters, I'm using iTerm and fish shell. I don't simply want to put eval (ssh-agent -c) into my fish config, because then I would still have to run ssh-add -K every time I open a new terminal window with the intention of using SSH. With the bundled agent, I only have to run ssh-add once, and it persists across sessions.

How can I accomplish this?

2
  • Do you have "Remote Login" enabled under System Preferences » Sharing? If yes, try disabling that. I'm not sure if that will solve the problem, but it turns on sshd, so I'm guessing that it might. Worth a shot at least, if you haven't tried it already.
    – TJ Luoma
    Commented Aug 25, 2021 at 21:58
  • @TJLuoma No, Remote Login is not enabled. I don't have any sharing items enabled, actually.
    – tiltowait
    Commented Aug 26, 2021 at 6:37

1 Answer 1

1

I'm using bash here (but the procedure must be easy to port to fish, zsh or other shell)

Run cat ~/.ssh/<yourkey>.pub which outputs something like this

ssh-<krypto gibberish> <some string>

Copy a bit of the <some string> part and add below:

KEYS=$(ssh-add -L)
if [[ "$KEYS" != *"<some string>"* ]]
then
    ssh-add -K .ssh/<yourkey> [optional other keys] >/dev/null
fi

The next time you open a terminal it will check if your key is loaded, and if not, load it.

I use the above solution since I have multiple keys for work etc, and that screws up the built-in ssh-agent auto-load as well.

3
  • The problem here is every single terminal window I open, it reverts to the in-built version of ssh-agent, which does not support security keys. Every window I open asks for my key's PIN, then fails to add the key because ssh-add is the correct version but ssh-agent is not.
    – tiltowait
    Commented Aug 27, 2021 at 22:49
  • Add the path to you ssh-add and see if that makes a difference then?
    – Fredrik
    Commented Aug 29, 2021 at 8:45
  • It's in the path. Oddly, it just ... started working the other day. No idea how or why. I didn't even reboot the system.
    – tiltowait
    Commented Sep 9, 2021 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .