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.

  • 4
    What are you actually trying to accomplish? If it's something like reloading the sshd config, you don't need to -- launchd starts a new sshd process on demand when an incoming connection is received, which means that the config is automatically reread for each new connection. OTOH, if you're trying to change the listener settings, those are controlled by launchd not the sshd config at all (see here). Sep 22 '12 at 1:47
  • 1
    This was just one test of debugging a password request from supposedly passwordless ssh using public keys. Turns out the thing I has missed was to turn off StrictMode Sep 22 '12 at 8:10

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.

  • This one gets me launchctl: Error unloading: com.openssh.sshd Apr 25 '14 at 4:27
  • 1
    @MattClark Then I suggest you stay away from production machines until you improve your reading comprehension. From my answer: "You can STOP the service ..." (emphasis mine). Jun 21 '16 at 16:27
  • 4
    You are correct, I did misread this, that was my fault. However, this also did not answer the question as it was asked.
    – Matt Clark
    Jun 21 '16 at 16:34
  • You can run this in one go with C-x C-e (C stands for Control). Paste it into the terminal, then C-x C-c to execute the emacs kill command, which will prompt you to save. I did this remotely and it did not kill my connection... given your config is correct.
    – Ray Foss
    Jun 24 '19 at 14:20

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
  • 2
    on moutain lion: launchctl stop error: No such process
    – RickyA
    Oct 10 '13 at 8:45
  • 1
    @RickyA: Worked fine on OSX Mavericks
    – neu242
    Oct 31 '13 at 9:19
  • Doesn't work here (launchctl stop error: No such process) Apr 25 '14 at 4:26
  • 1
    You need to sudo since that is how it is launched. Compare the running daemons/agents launchctl list | grep -i openssh vs sudo launchctl list | grep -i openssh. For reference read the launchctl link
    – glenschler
    Apr 25 '14 at 13:06
  • 1
    This should be accepted answer.
    – o01
    Sep 16 '20 at 5:54

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.