How do I start the ssh-agent at boot (or login) using Launchd?

462 views Asked by At

There's a plist in /System/Library/LaunchAgents/com.openssh.ssh-agent.plist. I've spent a couple hours trying to get it to start at boot/login, but I have had no luck yet. Most of my time has been spent trying to understand various launchctl commands, but I haven't found a combination that works yet. I've tried copying it to ~/Library/LaunchAgents, I've tried adding <key>RunAtLoad</key>, and everything else I can think of. I haven't had any luck figuring out how to view the debug logs either.

Since I'm likely doing something wrong, and the solution should be simple, it feels like trying to explain what I have been doing is not helpful in this case.

2 questions:

  • how do make a plist start on boot (or login)?
  • when the plist does fail to start, how can I see what's failing in the logs?

Here's the contents of the file:

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.openssh.ssh-agent</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/ssh-agent</string>
        <string>-l</string>
    </array>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SecureSocketWithKey</key>
            <string>SSH_AUTH_SOCK</string>
        </dict>
    </dict>
    <key>EnableTransactions</key>
    <true/>
</dict>
</plist>
1

There are 1 answers

0
asu On

If you run ssh-add -l or attempt to add a key ssh-add ... you should see the process. On reboot/login the process doesn't run until something tried to access the agent via SSH_AUTH_SOCK.