0

I currently have a file on serverB that I would like to transfer to my local computer. To get to serverB I first ssh to serverA then ssh to serverB. (e.g. ssh @serverA then inside serverA -> ssh @serverB)

Not sure what would be the best way to do this with scp?

  • 1
    scp uses the same connection and authentication methods as ssh. If you can't log on to serverB directly, you need to copy the file in two steps. – berndbausch Jan 24 '21 at 03:50

2 Answers2

1

You can use the ProxyJump option in ~/.ssh/config. From man ssh:

-J destination

Connect to the target host by first making a ssh connection to the jump host described by destination and then establishing a TCP forwarding to the ultimate destination from there. Multiple jump hops may be specified separated by comma characters. This is a shortcut to specify a ProxyJump configuration directive. Note that configuration directives supplied on the command-line generally apply to the destination host and not any specified jump hosts. Use ~/.ssh/config to specify configuration for jump hosts.

For example, your ~/.ssh/config may look like this:

Host serverA
Port 22

Host serverB Port 22 ProxyJump serverA

This will tell ssh to always connect to serverB via serverA, and it will do this for both normal ssh and for scp. In other words, you can type ssh serverB or scp serverB:big_file.txt . and it will know to route through ServerA. (You will, however, need a local copy of the key needed for serverB if you are using public key authentication.)

This is often referred to has "jump host" in ssh. A related config option in ~/.ssh/config is ProxyCommand.

0

one way is bitinerant solution and there are other ways.

  1. if you need more than one time, it is better use sshfs on serverA and scp from local to serverA
  2. if you need only one time, you could use ssh tunnel please follow this for tunneling and for sshfs
ssh to serverA
sshfs user@serverB:/foldertomount/ ~/mountpoint
scp ~/mountpoint/desiredFile LocalIP:/Path/