Add SSH Keys into Synology NAS
#===================================================================================================================================#
Add SSH Keys into Synology NAS
#===================================================================================================================================#
SSH into your Synology with your Chosen Port and keep a session open for your local computer as well
Enter the following into your terminal:
ssh-keygen -t rsa -b 4096 -C "name"
Save & Enter your Passkey Twice (Write it down somewhere too!)
Save the newly generated SSH keys in your local machines .ssh/config folder - you will need them shortly
NOTE: if your system does not have any .ssh folder under your users home directory, it is perfectly acceptable to simply mkdir -p ~./ssh/config - the system will recognize it as valid
SSH into your Synology Box (don't know how to do that? Please Refer to: Enable SSH in Synology)
Navigate to: /volume1/homes/<user> Check if you have an .ssh folder, if you don’t have one, you’re going to have to make one (it’s okay the system will recognize it):
Make a file named authorized_keys or edit the one that already exists
On your local machine, copy the entire oputput of the .pub key file you made earlier
In your synology, paste the entire Public Key into /.ssh/authorized_keys
Set the Correct Permissions on the Key with: chmod 600 authorized_keys
Next we will be editing the /etc/ssh/sshd_config file - search for PubkeyAuthentication - ensure that it is uncommented
Make sure this line is uncommented as well: AuthorizedKeysFile .ssh/authorized_keys
Make sure to set ownership of this file as well: sudo chown <user>:users /var/services/homes/cosmos/.ssh/authorized_keys
Restart the SSH Service with: sudo systemctl restart sshd
Back on your local system, go back to your .ssh directory (if not already there) and try to SSH into the Synology with: ssh -p 69 -i ~/.ssh/<SSH KEY> <user>@<SYNOLOGY IP>
If you can enter ssh <hostname> and get asked for the ssh key password, then congrats!