Brainless ssh-agent code for ZSH (or BASH) on macos
Probably near the top, after the point where the macos ssh-agent -l is
running via launchd
, but could be anywhere:
~/.zshrc
if ! ssh-add -l > /dev/null; then
ssh-add
fi
This ^ will call ssh-add
and prompt you for your passphrase
if, ssh-add -l
returns nonzero status (it prints The agent has no identities.
)
If ssh-add is storing a key, nothing happens so you WON'T be prompted for your ~/.ssh/id_rsa (ish) passphrase.
launchd
startsssh-agent
magically, by default (does it?):
❯ ps aux | grep -E 'ssh-agent|PID' | grep -v grep
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
leme 755 0.0 0.0 33626532 1400 ?? S 10:59PM 0:00.04 /usr/bin/ssh-agent -l
- I removed all the other junk dealing with
ssh-agent
in my [.zshrc | .bash_profile], rebooted and ran the aboveps
command to check the baseline - It's also likely that Gnome or X11/XDM might startup an agent on login, in which case, this is also all you may need