2

I've installed the latest version of OpenSSH on OS X using homebrew. As per the instructions in the formula, I have edited the org.openbsd.ssh-agent.plist file to point to /usr/local/bin/ssh-agent, and I have also added the following to my .zshrc:

eval $(ssh-agent)
function cleanup {
    echo "Killing SSH-Agent"
    kill -9 $SSH_AGENT_PID
}
trap cleanup EXIT

This means however, if I have n terminal tabs open, I have n running ssh-agent processes. Is this necessary? Surely I only need one instance of ssh-agent running at any time?

2

The original instructions say to put these lines into your .bash_profile. This means they are only executed for login shells. A shell inside a normal terminal usually isn't a login shell, hence the ssh-agnet is started only once.

The corresponding rc file for zsh is ~/.zprofile. So, put these lines not into ~/.zshrc, but into ~/.zprofile---et voilà.

If you want to know more about login, interactive, etc. shells, look into the shells' man pages, read this answer on UnixSE or my answer to another question.

  • Moving this code from .zshrc to .zprofile simple means that opening a new terminal tab results in a new ssh-agent process being started. They are however, now no longer being stopped as the tabs are closed. Saying that, I am using iTerm2 and every new tab starts with Last login... on a new ttys – Jonny Barnes Aug 14 '14 at 17:21
  • Is this behavior desired? If not, you should try to config your iTerm2 properly (do not invoke zsh as zsh -i). Unfortunately I cannot help you with that as I'm not using OSX. – mpy Aug 14 '14 at 17:46
  • Changing iTerm from using login shell to a specific command of /bin/zsh seems to have worked. – Jonny Barnes Aug 14 '14 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.