How to stop ssh-agent from being started on login/boot

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?


Solution 1:

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.