How can I use launchctl getenv over ssh?

Solution 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.