Bitwarden SSH agent environment variable on macOS not persisting after reboot

In the end I was able to fix the problem by mostly following the article I posted above:

  1. I created the following directory:
mkdir -p ~/Library/LaunchAgents
  1. I created a file named environment.plist in the same directory:
nano ~/Library/LaunchAgents/environment.plist
  1. I pasted the following XML content into the file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.d$
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>setenv.SSH_AUTH_SOCK</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/launchctl</string>
    <string>setenv</string>
    <string>SSH_AUTH_SOCK</string>
    <string>/Users/<user>/.bitwarden-ssh-agent.sock</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

Remember to replace <user> with your MacOS account username!

  1. Given that the environment variable wasn’t being set in the terminal I added the following code to my ~/.zshrc:
export SSH_AUTH_SOCK=$(launchctl getenv SSH_AUTH_SOCK)

Hopefully this will be useful to other MacOS users!

1 Like