I noticed ssh-agent is started automatically upon login. I'd rather it not do this, as I'd prefer oh-my-zsh to start the ssh-agent instead (since it automatically adds my id_rsa which is a nice feature).

I've tried tracking down where this is getting started, but I don't see anything. How do I disable it?


The launch daemon (launchd) is responsible for starting processes at boot, on demand, on schedule, in response to incoming network port connections and when a user is logged in.

You may get lucky with grep:

launchctl list | grep ssh-agent

In this case, it's the openssh prefernence that starts things:

launchctl list com.openssh.ssh-agent

I seriously prefer to edit these preference files with a tool like LaunchControl or Lingon. They give contextual help, graphical affordances and syntax checking. Apple's launchd/launchctl documentation exists but is dense, descriptive (rather than narrative / educational / prescriptive or basically easy to learn and use).

Here's an example how it shows an error with this specific agent on my Mac and a helpful warning that I need to disable SIP before futzing with this specific job or agent.

enter image description here

If you want to unload / disable this you need to find where the preference is stored then edit it or tell launchctl to unload (permanently) that item:

mdfind ssh-agent|grep plist
launchctl unload -w /System/Library/LaunchAgents/com.openssh.ssh-agent.plist
sudo launchctl disable system/com.openssh.ssh-agent

The daemons like this system one are being transitioned from the old "unload" syntax to the new "enable|disable" syntax, so you might get different results from my above commands on different versions and builds of macOS. Since you can see when it's running and kill it manually (killall ssh-agent) you should have good success with this extra info on launch daemon that's not on most articles for unix management of this ssh tool.

| improve this answer | |
  • Given all of the above, especially if SIP prevents you from disabling this directly, I would probably attack it a different way. The first idea that comes to mind would be to write my own launchd plist and have it run on load to have it run the commands to automatically stop ssh-agent, and then see if you can then get oh-my-zsh to restart / control it. You can put a launch plist in /Library/LaunchDaemons/ and have it run as root, which is probably what you need. I hope that helps. BTW if you do any work with launchd, I highly recommend LaunchControl. It's a great app. – TJ Luoma Aug 12 '18 at 21:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .