19.7 C
New York
Wednesday, June 18, 2025

launchd – Allow launchctl service that hundreds ssh keys on login


Coming from the Linux world, I’ve arrange my share of systemd daemons, however I’ve solely this morning been compelled to experiment with launchctl. My current replace to Sequoia has made it in order that I now need to manually run ssh-add after each boot. Having to do that from a terminal session breaks another workflows I’ve arrange, so I’ve the next saved as ~/.config/scripts/add-ssh-keys.sh:

#!/bin/bash

# Make sure the SSH agent is operating and add your key
if ! ssh-add -l > /dev/null 2>&1; then
  eval "$(ssh-agent -s)"
fi

# Add the personal SSH key to the agent
ssh-add -Ok ~/.ssh/my_private_key

I can simply verify that the ssh-add command works as written above when entered manually within the terminal. A fast ls confirms that the file is executable as I would flagged it. Subsequent, I’ve the next saved as ~/Library/LaunchAgents/com.person.addsshkeys.plist:





  Label
  com.person.addsshkeys
  ProgramArguments
  
    /bin/bash
    /Customers/myusername/.config/scripts/add-ssh-keys.sh
  
  RunAtLoad
  
  KeepAlive
  


I then ran launchctl load -w ~/Library/LaunchAgents/com.person.addsshkeys.plist and restarted my laptop. I run ssh-add -l and get the ‘agent has no identities’ error. If I run launchctl checklist | grep com.person.addsshkeys I see the service has a standing of 2. If I run log present --predicate 'eventMessage accommodates "addsshkeys"' --info, I see many messages alongside the next traces:

xpcproxy: Launch constraint set on 00000000-0000-0000-0000-000000000000 /Customers/myusername/Library/LaunchAgents/com.person.addsshkeys.plist
launchd: [gui/### [######]:] service inactive: com.person.addsshkeys

What am I lacking?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles