Command Line SSH restart Mac OSX Mountain Lion

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

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.


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.