When running ssh or scp from a script, there is a need to establish a connection to the remote site without being prompted for a password. This quick reference should get the job done.
Create Public Key Authentication
# ssh-keygen -t rsa
Press enter twice to create a key without a pass phrase. Then copy .ssh/id_rsa.pub to remote computer, placing it in the .ssh folder.
# scp .ssh/id_rsa.pub userid@xxxxxxx:.ssh/id_ras.pub
Logon to remote computer and build authorized key ring
To add the new key to the authorized keys, append the new key to authorized_keys file. Note the access level of the file should be 600. SSH is very picky about this and may not accept a less restrictive access setting.
# cd .ssh # cat id_ras.pub >> authorized_keys # chmod 600 authorized_keys
Finally, logout of the remote computer and logoff and log back on local/client computer – do not skip this step if you generated the key in this session.
Test the change by ssh to site. If no password is requested, it worked.
If the ssh test prompts for the password, then rerun ssh with the option -vvv to get the detailed debugging information.
1) Make sure you logged out of the local account and back in. This reloads the credentials.
2) Make sure the id_rsa.pub file was appended to the authorized_keys
3) Verify the permissions on the file (600 works for me on Fedora 14) and 700 on the .ssh folder.