Forum Discussion

Lachy's avatar
Lachy
Occasional Contributor
4 years ago

[174] Exporting SSH_AUTH_SOCK on macOS

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

sh
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:

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

```sh

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

3 Replies

  • Lachy's avatar
    Lachy
    Occasional Contributor

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

  • XIII's avatar
    XIII
    Super Contributor

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