Restart SSH/sshd in Mac OS X

To restart ssh/sshd service in Mac OS X, you can simply run the following two commands together:

sudo launchctl stop com.openssh.sshd
sudo launchctl start com.openssh.sshd

Your sshd will get restarted and your new ssh config file can be loaded as well.

p.s. Friendly reminding: DO NOT try to execute

sudo launchctl reboot com.openssh.sshd

instead since your computer will immediately get rebooted 🙂

SSH does not work after upgraded macOS sierra?

If you ever met the following errors when trying to git or ssh after upgraded your OS to sierra:

Unable to negotiate with legacyhost: no matching host key type found. Their offer: ssh-dss

Just relax, it’s not your fault but your server’s fault. Upgrading your OS to sierra will also bump your OpenSSH from version 6.9 to 7.2. According to the document of OpenSSH 7 (http://www.openssh.com/legacy.html):

OpenSSH 7.0 and greater similarly disable the ssh-dss (DSA) public key algorithm. It too is weak and we recommend against its use. It can be re-enabled using the HostKeyAlgorithms configuration option:

ssh -oHostKeyAlgorithms=+ssh-dss user@legacyhost

or in the ~/.ssh/config file:

Host somehost.example.org
    HostKeyAlgorithms +ssh-dss

However, it is probably not enough. You may be prompted for password all the time but no password is correct. In that case, you can simply append another line in your ~/.ssh/config file:

    PubkeyAcceptedKeyTypes +ssh-dss

That’s it! Don’t forget to restart your sshd service before retrying.