ssh or rsync without password and sshpass

Posted under » Linux on 27 Dec 2018

You may have read about using ssh, SCP and rsync but all require password which is understandable because of security. BTW... this is not recommended for a business environment. However, there are times where you need to do this in cron so you need to do this without intervention.

First, use ssh-keygen on local server to generate public and private keys. Note: When it asks you to enter the passphrase just press enter key, and do not give any password here.

$ ssh-keygen
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Next copy the key over to the target server.

ssh-copy-id -i ~/.ssh/id_rsa.pub lkybasta@192.168.200.10

Note: The above will ask the password for your account on the remote host, and copy the public key automatically to the appropriate location.

Afterwhich you should try ssh, scp or rsync and it will not ask you for password.

If this doesn't work because of differenc OpenSSH configuration, you can try the sshpass method. 1st, apt install sshpass.

sshpass -p "shanmugam" scp -r dick@papundek.com:/some/remote/path /some/local/path

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data