This one helps me a lot easier backing up the files from one server to backup server without password prompt.
Thanks to Lubos Rendek on his post at http://linuxconfig.org/Passwordless_ssh you make my life easier hahahah.
Follow the steps below
1. Generate ssh key on Local Server
[admin@localserver .ssh]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/admin/.ssh/id_rsa.
Your public key has been saved in /home/admin/.ssh/id_rsa.pub.
The key fingerprint is:
12:d7:c2:24:18:07:ac:49:25:34:d0:f1:ed:e5:5a:6e admin@localserver
The key’s randomart image is:
+–[ RSA 2048]—-+
|.+=+++o . |
| o+oo + . |
| . o. o = . |
| o . = . |
| o S |
| = |
| . E |
| . |
| |
+—————–+
2. Check the file if properly generated
[admin@localserver .ssh]$ ls -la
total 20
drwx——. 2 admin admin 4096 Aug 19 11:40 .
drwx——. 32 admin admin 4096 Aug 19 11:37 ..
-rw——-. 1 admin admin 1679 Aug 19 11:40 id_rsa
-rw-r–r–. 1 admin admin 400 Aug 19 11:40 id_rsa.pub
-rw-r–r–. 1 admin admin 2740 Aug 18 14:52 known_hosts
3. Copy ssh id to Backup Server
[admin@localserver .ssh]$ ssh-copy-id admin@backupserver
admin@backupserver’s password:
Now try logging into the machine, with “ssh ‘admin@backupserver'”, and check in:
~/.ssh/authorized_keys
to make sure we haven’t added extra keys that you weren’t expecting.
4. Login to Backup Server
[admin@localserver .ssh]$ ssh admin@backupserver
Last login: Thu Aug 18 17:22:33 2011 from 192.168.1.7
[admin@backupserver~]$ logout
Connection to backupserver closed.
[admin@localserver .ssh]$
5. Create Backup Script
[admin@localserver Downloads]$ vi new-rsync.sh
#!/bin/bash
RSYNC=/usr/bin/rsync
$RSYNC -ave ssh /home/admin/Downloads/temp admin@backupserver:/home/admin/Documents
6. Save the script (:wq!)
chown 755 new-rsync.sh
7. Test the script
[admin@localserver Downloads]$ ./new-rsync.sh
sending incremental file list
sent 87 bytes received 13 bytes 66.67 bytes/sec
total size is 5309440 speedup is 53094.40
8. Create Cronjob
crontab -e
add
# BACKUP
00 00 * * * /home/admin/Downloads/new-rsync.sh
Done!