To set up SSH server on Mac OS X (tested on Sierra, and likely works for other OS X versions):
- Open Terminal, and run
sudo nano /etc/ssh/sshd_config
- Make sure the line for
PubkeyAuthentication
is uncommented, and is set to yes. It should looke likePubKeyAuthentication yes
. Save the file. - Go to Preferences > Sharing
- Check "Remote Login"
- Select "Only these users:", and remove all users from the list except your own user.
- From the client, open the Terminal and generate an SSH key:
ssh-keygen
. It is best to call it something that describes your SSH server, so that you don't reuse the key with other SSH servers. - Run
ssh-copy-id -i ~/.ssh/private_key user@sshserverhostname
- On the SSH server, verify that the public key was added to
~/.ssh/authorized_keys