Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Tuesday, March 31, 2020

Using jumphost to scp and ssh without ssh / scp twice

Jumphost comes handy in the cases where A (source) -> C (dest) direct ssh or scp is not possible due to firewall policies. So it is achieved via a Jumphost B, rather than repeating the process twice, A -> B and then B -> C.

scp -o 'ProxyJump me@jumphost.bmi.emory.edu' test.log pkathi2@desthost.bmi.emory.edu:/opt/localdrive

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 &

ssh: connect to host xxx.xxx.xxx.xx port 22: Connection refused lost connection

This is one of the commonest errors that are thrown when trying to copy files over scp. The major reason for this is, the port being different from the default 22.
 
pradeeban@pradeeban:~$ scp -r /home/pradeeban/patches root@116.12.92.113:/mnt/patches
ssh: connect to host 116.12.92.113 port 22: Connection refused
lost connection
To fix this, use -P flag, and the port number. Notice the upper case. This is to maintain the consistency with the -p usage of cp command.
pradeeban@pradeeban:~$ scp -P 1984 -r /home/pradeeban/patches root@116.12.92.113:/mnt/patches