[174] Exporting SSH_AUTH_SOCK on macOS

Lachy
Lachy
Community Member
edited May 2022 in SSH

The documentation for exporting SSH_AUTH_SOCK on macOS is wrong. When using it exactly as specified using the quoted string:

export SSH_AUTH_SOCK="~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"

Running ssh-add -l shows this error: "Error connecting to agent: No such file or directory"

The correct approach is to not have it in quotes and to escape the space character:

export SSH_AUTH_SOCK=~/Library/Group\ Containers/2BUA8C4S2C.com.1password/t/agent.sock

This resolves the path correctly to /Users/yourusername/Library/.... and ssh-add -l outputs the keys as expected.

Or alternatively, here's a useful snippet to put in your ~/.profile (for Bash users) that retains compatibility with keychain where 1Password is not used. This is particularly useful for people who sync their ~/.ssh/config between computers, and don't have 1Password 8 beta on all of them yet.

# Obtain the major version of macOS
IFS='.' read -r -a MACOS_VERSION <<< $(sw_vers -productVersion)
SSH_AUTH_SOCK_FILE=~/.1password/agent.sock
if [ -h $SSH_AUTH_SOCK_FILE ]; then
  #echo "Using 1Password SSH Agent"
  export SSH_AUTH_SOCK=$SSH_AUTH_SOCK_FILE
else
  #echo "Using MacOS Keychain"
  if [[ "${MACOS_VERSION[0]}" -ge 12 ]]; then
    #echo "macOS Monterey or later"
    ssh-add --apple-load-keychain
  else
    #echo "macOS Big Sur or earlier"
    ssh-add -A
  fi
fi

(You can uncomment the echo lines for debugging purposes. If you use zsh or other shell, you may have to adjust it)


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided

Comments

  • XIII
    XIII
    Community Member

    /Users/username instead of ~ in the original example also works (the ~ does not).

  • Lachy
    Lachy
    Community Member

    Yes, also using "$HOME/Library/…" works too. Variables get expanded in strings, tilde doesn’t.

  • This was a bug in the docs, has been fixed now!

This discussion has been closed.