Command Line SSH restart Mac OSX Mountain Lion

How can I restart the SSH service via the command line on Mac OSX Mountain Lion please?

Using ps aux | grep 'ssh', I was able to deduce that the process is most likely /usr/sbin/sshd.

From here I searched the sshd documentation for references to 'restart' but found none.

I don't know what my next step should be.


See this answer to a similar question on ServerFault. The command should be the same in Mountain Lion.

You can stop the service using the 'unload' subcommand.

sudo launchctl unload  /System/Library/LaunchDaemons/ssh.plist

Update suggested by @MattClark: To restart the service use load after unload:

sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Note that existing SSH sessions will be terminated, so you need to run this independent of the current user session.


There is no reason to 'unload' the sshd service, when instead you can just 'Stop' the sshd service. It will restart on it's own.

sudo launchctl stop com.openssh.sshd

I couldn't confirm Ansgar's answer worked as there were no messages / obvious signs though I'm confident it did.

I also found killall sshd which kills and restarts sshd processes with the disadvantage that any connections are stopped.