FiloSottile / yubikey-agent

yubikey-agent is a seamless ssh-agent for YubiKeys.
https://filippo.io/yubikey-agent
BSD 3-Clause "New" or "Revised" License
2.6k stars 124 forks source link

How can I start yubikey-agent as a service on Mac (without brew) #138

Open etorreborre opened 1 year ago

etorreborre commented 1 year ago

Hi, I installed yubikey-agent via Nix, and more precisely via flox, which means that I am not using Homebrew. The user manual says that I should be able to use launchctl to start yubikey-agent as a service but unfortunately I don't know how to do this.

Is there like a two-liner which can do this or is the setup more involved? Thanks for your guidance.

artyom commented 1 year ago

Create a $HOME/Library/LaunchAgents/io.filippo.yubikey-agent.plist file with the content similar to this:

<?xml version="1.0" encoding="UTF-8"?>
<!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>io.filippo.yubikey-agent</string>
    <key>Program</key>
    <string>/Users/artyom/go/bin/yubikey-agent</string>
    <key>ProgramArguments</key>
    <array>
        <string>yubikey-agent</string>
        <string>-l</string>
        <string>/tmp/yubikey-agent/yubikey-agent.sock</string>
    </array>
    <key>ProcessType</key>
    <string>Standard</string>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/tmp/yubikey-agent.stdout</string>
    <key>StandardErrorPath</key>
    <string>/tmp/yubikey-agent.stderr</string>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
        <key>SockPassive</key>
        <false/>
        <key>SockPathName</key>
        <string>/tmp/yubikey-agent/yubikey-agent.sock</string>
        </dict>
    </dict>
</dict>
</plist>

Tweak it appropriately, at minimum, replace path to yubikey-agent binary (it's /Users/artyom/go/bin/yubikey-agent in that snippet).

Once you have this file in place, start the service by running

launchctl load $HOME/Library/LaunchAgents/io.filippo.yubikey-agent.plist