Tuesday, December 13, 2011

scp - Copying files between two remote locations

Say, now you are going to copy a few files from a remote server to another. As usual, your remote_server_1 should be given the credentials to copy files to remote_server_2.

root@node2:~# scp -P 1984 -r /mnt/patches root@116.12.92.114:/mnt/patches

Usually, your computer key must already have given the required permissions to access those remote locations. But since the access is not given to remote_server_1, it will prompt for the password of remote_server_2.
As a quick fix, you can copy the private key from your local computer to remote_location_1. However, further discussion on the security concerns on doing this can be found on the web.

scp -P 1984 ~/.ssh/id_rsa root@116.12.92.113:~/

Now if you encounter the below when trying,
root@node2:~# scp -P 1984 -r -i id_rsa /mnt/patches root@116.12.92.114:/mnt/patches
ssh_exchange_identification: Connection closed by remote host
lost connection

Have a look into the denied and accessed hosts of remote_server_2, and make sure that the ip of remote_server_2 is allowed and not denied.

vim /etc/hosts.deny
vim /etc/hosts.allow
#sshd sshd1 sshd2 : ALL : ALLOW
sshd: 116.12.92.113

Now, the scp command given above, should work as expected to copy the files from the remote_server_1 to remote_server_2.


Later update: I found rsync to be more efficient.

nohup rsync -avz /source root@116.12.92.113:/home/destination-root &

No comments:

Post a Comment

You are welcome to provide your opinions in the comments. Spam comments and comments with random links will be deleted.