I want to set the value of SSH_AUTH_SOCK to a different location on an OSX El Capitan system. I attempted to do so by executing the following command:

$ launchctl setenv SSH_AUTH_SOCK ~/.gnupg/S.gpg-agent.ssh

However, SSH_AUTH_SOCK still holds the default value even after I restart the terminal:


But interestingly, when I query the value of SSH_AUTH_SOCK using launchctl, I get the desired result:

$ launchctl getenv SSH_AUTH_SOCK

How can I correctly set the value of SSH_AUTH_SOCK system-wide?

EDIT: SSH_AUTH_SOCK was not set in any of the shell startup files (e.g. ~/.zshrc, /etc/zshrc, /etc/zprofile)

  • Did you try to re-login or reboot? – Jakuje Sep 3 '16 at 6:06
  • @Jakuje Yes, but the problem persisted after reboot. – Sora Minazuki Sep 3 '16 at 13:10
  • 1
    Run into absolutely same issue! I know it's 2 years old question, but did you manage to solve it? This still persists on High Sierra. So weird... Even Apples launchd doesn't work on their own OS as expected... – Drew Jun 6 '18 at 23:56
  • Unfortunately, I haven't been able to find a direct solution. However, it is possible to work around this particular problem by using the IdentityAgent option in SSH_CONFIG. – Sora Minazuki Jun 7 '18 at 1:20

This is mostly extracted from the excellant post here.

You need to make a plist file in your ~/Library/LaunchAgents directory with the following content.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <string>/bin/ln -sf $HOME/.gnupg/S.gpg-agent.ssh $SSH_AUTH_SOCK</string>

Should do the trick.

  • This is a workaround, but doesn't really answer the specific question of how to actually set SSH_AUTH_SOCK to an arbitrary value system-wide. Which I'd love to know the answer to. As mentioned launchctl setenv doesn't seem to work for that particular environment variable. – matthew Feb 28 '19 at 16:28

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.