Skip to content

Instantly share code, notes, and snippets.

@partikus
Forked from lmb/README.md
Created November 13, 2023 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save partikus/cd45013b1274af8ae63b17030d89176c to your computer and use it in GitHub Desktop.
Save partikus/cd45013b1274af8ae63b17030d89176c to your computer and use it in GitHub Desktop.
macOS: use ssh-agent from homebrew

This recipe allows you to use the ssh-agent from homebrew with the auto generated SSH_AUTH_SOCK in /private/tmp. It works because disabling com.openssh.ssh-agent doesn't stop launchd from allocating SSH_AUTH_SOCK. com.homebrew.ssh-agent spawns a shell to remove the socket and then execute the homebrew ssh-agent.

  1. Install openssh from homebrew
  2. Disable the built in macOS agent: launchctl disable gui/$UID/com.openssh.ssh-agent
  3. Copy com.homebrew.ssh-agent.plist into ~/Library/LaunchAgents
  4. Enable the new agent: launchctl bootstrap gui/$UID com.homebrew.ssh-agent.plist
  5. Ensure that the correct agent is running:
    % launchctl list | grep ssh
    -	0	com.openssh.ssh-agent
    23986	0	com.homebrew.ssh-agent
    
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.homebrew.ssh-agent</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<!-- We reuse SSH_AUTH_SOCK from com.openssh.ssh-agent -->
<string>rm -f $SSH_AUTH_SOCK; exec /opt/homebrew/bin/ssh-agent -D -a $SSH_AUTH_SOCK</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment