9

I need to upload and compile stuff on a remote machine that is only reachable inside a specific network that I can access over SSH.

So for example I perform the following steps:

me@mymachine$ ssh user@network_gateway
user@network_gateway$ ssh seconduser@targetmachine
seconduser@targetmachine$ #do stuff

Is there a way to make my local machine aware of the tunneling without undergoing the trouble of connecting to the network gateway every time?

1
  • 1
    Is there a reason you can't setup a VPN? – MDMoore313 Mar 23 '14 at 11:21
17

You can configure your .ssh/config to provide a tunnel automatically for the targetmachine. For this to work passwordlessly, you need to set up public key authentication in both hosts and agent forwarding in the gateway, though.

Set it up so a connection to targetmachine is proxied through network_gateway:

Host targetmachine
  HostName targetmachine.company.com
  ProxyCommand ssh network_gateway -W %h:%p

Then you can issue:

$ ssh targetmachine

to connect directly. There's more info in the ssh_config(5) manpage.

1
  • Alternatively you can forward ports from network_gateway. – Boris the Spider Mar 23 '14 at 0:42
2

SSH will take a command to be executed on the remote machine. For example, to SSH into server2 via server1:

ssh alice@server1 "ssh bob@server2"

Then you will be able to type commands into server2's prompt.

If you want to get even more fancy, you can nest them:

ssh alice@server1 "ssh bob@server2 \"cd myproject && git pull origin master && make all\""
0
2

You could use a script like ssh-chain to make your life easier.

No idea if it supports sftp transfers, though.

Not the answer you're looking for? Browse other questions tagged or ask your own question.