How to set up a Trusted SSH Connection using Private and Public Keys

0
75

SSH into your NAS using your preferred SSH client:

ssh admin@192.168.1.xx

Generate the SSH key pair:

ssh-keygen -t rsa -b 4096

Copy the Public Key to the Web Server

ssh-copy-id user@webserver.com 
or do it manually if ssh-copy is not installed

Copy the Public Key Manually to the Web Server

ssh user@webserver.com
mkdir -p ~/.ssh
chmod 700 ~/.ssh

go to NAS to copy public key
scp ~/.ssh/id_rsa.pub user@webserver.com:~/.ssh/temp_key.pub

//append to  authorized_keys, clean up and set permissions
ssh user@webserver.com 
cat ~/.ssh/temp_key.pub >> ~/.ssh/authorized_keys
rm ~/.ssh/temp_key.pub
chmod 600 ~/.ssh/authorized_keys

//test
exit
ssh user@webserver.com

If you are connecting and not using the root account

mkdir -p /var/services/homes/userName/.ssh
cp /root/.ssh/id_rsa /var/services/homes/userName/.ssh/

chown -R  userName:users /var/services/homes/userName/.ssh
chmod 700 /var/services/homes/userName/.ssh
chmod 600 /var/services/homes/userName/.ssh/id_rsa
// prevents prompt
ssh -o StrictHostKeyChecking=no root@ftp.trinijunglejuice.com

This will:

  • Automatically accept the new server’s key without prompting.
  • Add the key to the known_hosts file for future connections.