In a terminal session I can run launchctl getenv SSH_AUTH_SOCK and it prints the value of that variable. However if I ssh into the same user from another computer, then run the same command, there is no output. I'd like to know how to make this work.

This is important to me because:

  1. my ssh keys have passphrases
  2. my terminal prompt includes bash-git-prompt
  3. this leads to the message Enter passphrase for key [~/.ssh/...]: being printed every time my prompt is written to the screen when I don't have access to the ssh agent socket.
  4. launchd sets the ssh agent socket path so that it can use the fancy "only runs when needed" functionality of launchd, so I don't know the path ahead of time and it changes on reboot.

1 Answer 1


What you're describing is how things are supposed to work. The reason that commands leaves no output is not that some bug or error happened that prevents it from displaying the value of SSH_AUTH_SOCK - it is simply because that variable is not supposed to be set by launchd in your environment.

When you're using key based authentication with SSH, and you want an agent to make it easier to handle the private keys - you'll want to run that agent locally. I.e. when you're ssh'ing into a remote computer, the agent is supposed to run on your local computer that you're ssh'ing from.

Imagine that you're ssh'ing in to a remote computer, and then want to use ssh from there and you need to enter a passphrase - the prompt pops up in the GUI shown on the monitor connected to that remote computer. You can't see it, you can't act with it. This is not how it's supposed to work.

Instead run ssh agent on your local computer, load in the keys, and then ssh into your remote computers using the -A parameter for ssh to enable agent forwarding (or set it permanently for that remote computer in the configuration).

If you really want to run ssh-agent on the remote computer, you can ofcourse do so. When you have ssh'ed to the remote computer, simply run ssh-agent and add your keys. If you want to automatize running ssh-agent, you can do that.

You must log in to answer this question.

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