One time I need to add access my MacBook Pro remotely using ssh from a Windows 10 machine.
It’s very easy actually to enable ssh server on macOS.
You just need to open System Preferences → Sharing → check Remote Login and that’s it.
Simply connect it using your client machine with ssh username@ip-address.
The problem is, by default this ssh server only accept password login.
To enable passwordless login using private key authentication, we need to configure further.
Open your favorite terminal application on your macOS.
Edit sshd_config file using your favorite text editor.
The file is located at /etc/ssh/sshd_config.
Since it requires admin credential, you need to edit it using sudo.
Here is an example using vim editor.
Edit only two properties: PasswordAuthentication and ChallengeResponseAuthentication.
Set them both to no.
Create authorized_keys file if you don’t have one.
Enter your other machines’ public key in authorized_keys file.
Recheck Remote Login configuration again to restart ssh server on your macOS.
Now try again login via ssh.
This time it won’t ask you for a password.
Here is the complete sshd_config file on my macOS in case you want to compare it with yours.