Lanston
Lanston

Reputation: 11844

How to copy files to a remote machine through a jumping machine by scp command

say that the target machine is [email protected] and the only place to login is [email protected](usually called jumping machine)
and how can I copy local files to machine B using the scp command
I've tried scp files [email protected] but nothing happens,it only told me sort of Operation Time Out

Upvotes: 5

Views: 5727

Answers (2)

cortex
cortex

Reputation: 86

This is what you were looking for:

scp -J user@targetMachineA ./local_file_or_directory user@targetmachineB:/path/where/to/copy/

from scp man page:

-J destination Connect to the target host by first making an scp 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. This option is directly passed to ssh(1).

Upvotes: 4

Xerus
Xerus

Reputation: 136

I'm not sure it's the best solution but , you can use the tcp port forwarding feature include in ssh.

first be sure the jumping machine have the Tcp Forwarding enable look into sshd_config file, usually locate in directory "/etc/ssh/" . Check if you have the entry:

AllowTcpForwarding no

By default TcpForwarding is enable, so if it's not disable it's suppose to be ok.

You will establish a connexion on the jumping machine and creation a port fording port locally on your system to communication directly to the system B

the ssh command to run on your workstation will be :

ssh -L 2222:server_B:22 server_A

from the ssh man page:

-L [bind_address:]port:host:hostport
Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and a connection is made to host port hostport from the remote machine

So to send file to the server B , from your workstation:

scp -P 2222 Your_file 127.0.0.1:/PATH_ON_SERVER_B

Have a nice day.

Upvotes: 0

Related Questions