Transfer files between two remote SSH servers
If you are on an Ubuntu version that is still supported, then
your scp
command will provide the -3
switch which enables
copying files from remote1 to remote2 via localhost:
me@local:~> scp -3 user1@remote1:/path/to/file1 user2@remote2:/path/to/file2
You can also omit the -3
switch, but then you will need the
public key (id_rsa.pub
) of user1@remote1
in the
file authorized_keys
of user2@remote2
:
me@local:~> scp user1@remote1:/path/to/file1 user2@remote2:/path/to/file2
scp
then under the hood does a ssh user1@remote1
first and from there
scp /path/to/file1 user2@remote2:/path/to/file2
. That's why the credential must be
distributed different from the -3
solution.
In other words:
scp -3 remote1:file1 remote2:file2
transfers the file from remote1 to localhost and then back to remote2. The data travels remote1 → localhost → remote2. The localhost is the 3rd party in this scenario, hence-3
. For this to work, you will need the credentials from localhost on both remote1 and remote2 because localhost connects to both of them.scp remote1:file1 remote2:file2
copies the file directly from remote1 to remote2 at the speed with wich they are connected to each other. localhost is not involved here (besides issuing the command). The data travels remote1 → remote2. For this to work, you will need the credentials from localhost only on remote1 but additionally you need the credentials of remote1 on remote2 because localhost connects to remote1 only and then remote1 connects to remote2.
If possible I would choose the second approach. As some comments already
say: usually often the network cable between remote1 and remote2 is
far thicker than the cable between them and localhost.
In most cases, two ssh servers can reach each other (or at least one can reach the other), and again in most cases the workstation's internet is far worse than either of the servers.
If so, ordering one server to transfer to the other one is the way to go.
ssh server1 nohup scp somefile server2:somefile
Check nohup.out
on server1 for errors.
If server reachability is the other way around you can reverse which machine is the master:
ssh server2 nohup scp server1:somefile somefile
Perhaps you could use one of several GUI front-ends to rsync:
Is there any GUI application for command rsync?
Or perhaps you could use rsync directly from the command line to connect to both remote servers:
"How to rsync files between two remotes"
I often log in to one server with ssh, then from that server's command line use rsync to push or pull files to the other remote server -- that's generally much quicker than trying to transfer the files through some 3rd computer.
The rsync is smart enough to do some work, then if anything goes wrong and interrupts the process, it can later resume right where it left off.