You are on page 1of 2

Copying files between linux machines using scp

and ssh without linux user passwords

PREPARED BY RAVI KUMAR LANKE

Page 1

1. Setup ssh keys on both machines


To generate a public / private key pair :
$ ssh-keygen -t rsa
The above will generate 2 files, ~/.ssh/id_rsa (private key) and /home/ oracle /.ssh/id_rsa.pub (public key)
To setup the SSH keys for usage (one time task) : Copy the contents of /home/ oracle /.ssh/id_rsa.pub of source server and paste in a new line
of /home/ oracle /.ssh/authorized_keys of destination server
If /home/oracle/.ssh/authorized_keys doesn't exist, feel free to create it.

2. To copy files use the below command


change to destination directory in destination server and run the below command
$scp -i ~/.ssh/id_rsa oracle@source_server_hostname:/u01/oracle/backup/*.* .

Cron job :
make a shell script as below and save it as filescopy.sh:
#!/bin/sh
backup_dir="/home/oracle/ backup"
cd $backup_dir
scp -i ~/.ssh/id_rsa oracle@source_server_hostname:/home/oracle/backup/*.* .

Now run the cron job on the destination server with above script
$crontab -e
Enter the below line
*/2 * * * * /u01/filescopy.sh > /u01/backup.log 2>&1
save and exit
It will copy the files into the destination server for every 2 sec.

PREPARED BY RAVI KUMAR LANKE

Page 2

You might also like