I’m working on an automated rsync script that requires remote access to another machine on the local network. The easy and secure way to accomplish this is to connect using SSH. The problem I found while testing the script is that it will not run because it’s prompted by the remote machine for a password each time. Okay I’ll just use key-only login which doesn’t require passwords, easy enough, right? Well.. though the commands were simple enough to configure SSH login this way I couldn’t ever get it working properly. I gave it one last try using ssh-keygen and actually got it working! I thought I’d share the process I followed for success in case anyone else is experiencing the same headache:
I’m using 2 machines. “localpc” is the machine which will run the script so I want passwordless login to the other host. “remotepc” is the machine I wish to login to.
Clear your .ssh/ directory on both localpc and remotepc for the user you wish to login as. This helps to start from scratch with no possible issues in the key files.
sudo rm –R /home/user/.ssh/*
Login to localpc from remotepc through SSH normally:
ssh user@localpc
and do the same from the other machine:
ssh user@remotepc
I’m not completely sure why but this helps alleviate a “no identities error” that can happen later on.
On localpc:
Create an RSA key:
ssh-keygen –t rsa
Chose the default Save location (Just press Enter)
Chose no passphrase (Press Enter again)
On localpc:
ssh-copy-id -i /home/user/.ssh/id_rsa.pub user@remotepc
Make sure and change the user and remotepc to the names that represent your setup.
You’re Done! Test it out.
On localpc:
ssh user@remotepc
