ssh tunnelling through gateway

Need to log in through a gateway to get access to a box at work? ssh tunnels can make your life easier.

+-------+     +------------------+    +---------------+
|  me   |-----| gateway.work.com |----|  box.work.com |
+-------+     +------------------+    +---------------+

Create an ssh tunnel through the gateway

 ssh -N -L 12345:box.work.com:22 me@gateway.work.com

Now, localhost port 12345 is tunnelling straight through to box.work.com port 22.

Which means you can ssh to box.work.com by doing

ssh -p12345 me@localhost

You can scp files through this connection with something like:

scp -o"Port=12345" localhost:/home/me/some_file.txt .

Or rsync with something like:

rsync -av -e "ssh -p12345" \
me@localhost:/home/me/some_folder .

Or even mount a remote directory as a local filesytem like:

 sshfs localhost:/some_folder_on_remote_box \
 /some/local/mount_point -o port=12345
Advertisements

4 responses to “ssh tunnelling through gateway

  1. Pingback: Revisiting SSH Tunneling Tricks « Dave's Blogs

  2. Very good. This is the clear example I needed to understand how it works.

  3. Reblogged this on Simplex Signum Veri and commented:
    When I was in UT Austin, I could directly connect to any machine of our department via ssh. However, now in Georgia Tech, we have to ssh to a gateway, which cannot be used for computing, before we can ssh to any department owned machines. This made it hard if I want to use functions such as using Matlab GUI remotely via “ssh -X”. (Unfortunately, Math@GT does not provide NoMachine NX, which I used very often in Math@UT…. ). This article taught me how to “tunnel through” the gateway.

  4. This is an open-source software having SSH gateway – https://www.ezeelogin.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s