I'm trying to copy a file from one remote server to another remote server from my local machine.
Here's what I'm trying to do
localA $ scp userB@remoteB:/path/to/file userC@remoteC:/path
The problem is that I need to pass two passwords for both userB and userC on the remote machines.
According to Garron the above should work, but I got permission denied.
Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive).
lost connection
Any suggestions?
This questions already exists on Superuser:
https://superuser.com/questions/686394/scp-between-two-remote-hosts-from-my-third-pc
scp -3 user1@remote1:/home/user1/file1.txt user2@remote2:/home/user2/file1.txt
As described there -3 option instructs scp to route traffic through the PC on which the command is issued.
The above is true if remote1 and remote2 are on the same network.
In case not:- You have to use port forwarding
If you can ssh to both remote servers from your local (local -> remote1 & local -> remote2), then you could try:
ssh -A -t user1@remote1 scp srcpath user2@remote2:destpath
This will transfer straight from remote1 to remote2 using your local credentials all the way.
If you do not want to be asked for passwords, then you should set up the authorized_keys file on remotes.
This is possible using the following command line in linux terminal :
scp -3 user1@ip:path/from/directory/ user2@ip:path/to/directory
a prompt will appear asking for passwords like this:
user1@ip's password: user2@ip's password:
If you give both passwords in order by pressing enter after the first password, it should accept but it wont. Even if you give both passwords again in order but by not pressing enter after the first password, it wont accept again.
You have to give user2's first, then press enter and then type user1's password and press enter. This will work.
I know it doesn't sounds right, but only this will work. This is a bug in scp.
You only need passwords if you don't have entries in the authorised_keys file. Once you have logged in to the 2 servers (localA -> remoteB & remoteB -> remoteC) and established the secure connection your original command should work.
I find -o "ForwardAgent yes”
does the trick:
localA $ scp -o "ForwardAgent yes” userB@remoteB:/path/to/file userC@remoteC:/path
I like this better than the -3
since I don't want a middle machine slowing things down. I like @RubenCaro answer too, but this seems more direct.