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?

mightyuhu
  • 197
  • 1
  • 4

3 Answers3

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.

dawud
  • 15,096
  • 3
  • 42
  • 61
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\""
Kevin Chen
  • 178
  • 5
2

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

No idea if it supports sftp transfers, though.

zhenech
  • 1,492
  • 9
  • 13