Issues with using Jump Host

2019-06-14 22:07发布

问题:

How do i transfer a file from my local machine to a remote host to which i need to get through a jump host? These are the steps i follow to connect to the remote host

1. ssh myname@jump-host
2. enter password
3. sudo su - another-random-name
4. ssh name@remote-host

Now i want to transfer a file from my local machine to the remote-host. How would i achieve this? I have already tried scp -oProxyCommand but i dont quite know where i should include step 3 as part of this command?

回答1:

On the jump host under another-random-name run

ssh -L 2222:remote-host:22 myname@jump-host

then on your local computer you can run

scp -P 2222 file name@jump-host:

SCP will try to connect to jump-host, while in fact this connection will be forwarded to jump-host. And will use name as it is connecting to remote-host. You are probably still facing problem with certificate for another-random-user. You can either create certificate on your machine for your-local-user and put public key on remote-host in user allowed keys.



回答2:

Use port forwarding to get third host ssh port on your localhost, in this way:

ssh -L 2222:remote-host:22 myname@jump-host

then (on another tab/shell on first host):

scp -P 2222 file myname@localhost:

will copy directly to remote host.