Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by Jenny D, Scott Pack, Katherine Villyard, Dave M, Michael Hampton Mar 23 at 20:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Is there a reason you can't setup a VPN? –  BigHomie Mar 23 at 11:21

3 Answers 3

up vote 17 down vote accepted

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.

share|improve this answer
    
Alternatively you can forward ports from network_gateway. –  Boris the Spider Mar 23 at 0:42

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\""
share|improve this answer

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

No idea if it supports sftp transfers, though.

share|improve this answer

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