MacOS SFTP Public Key Authentication

ftpssh

We can enable SFTP on our MacOS by going into System Preferences -> Sharing -> Remote Login

This works fine and we can easily connect to our local server by sftp localhost and then provide the password of the current user.

Now, some professional FTP Servers, allow you to connect to the FTP server by using a SSH key. (so you don't have to enter username/password).

https://www.cerberusftp.com/products/features/public-key-authentication/

I wonder if the SFTP server on MacOS can also be configured to authenticate users using keys rather than raw username/password.

Best Answer

Oh I found the answer. we just have to add the public key to the authorized_keys file

cat ~/.ssh/id_rsa.pub | ssh localhost "cat >> ~/.ssh/authorized_keys"