How to use ssh tunnel from local machine

pavan kumar ceemala
2 min readMar 16, 2021

--

Photo by Ricardo Gomez Angel on Unsplash

There are scenarios where you have your applications hosted inside a secured network and you can access these application only thru your jump box.

These jump boxes can be a windows or linux based servers, which are allowed to access your applications(thru IP whitelisting on the firewall or AWS EC2 security groups).

In this article, I will show how we can extend this IP forwarding or ssh tunnel to access the secured application from our local machine.

Lets understand the basics here.

SSH tunnel: SSH tunneling or SSH IP forwarding is a method of transporting arbitrary networking data over an encrypted SSH connection.

Bastion Host: A server which is located inside your network and used to access your secured application. Usually these jumbox/bastion hosts are available to connect only from your company network or secured VPN.

How to setup this on our local desktop windows/Mac

  1. Install git bash(for mac user this is not required)
  2. I’ve one api and and one front-end applications which are hosted inside the secutiry network, these two URLs are accessible only from my jumpbox, to make these available from my local machine, we need to edit the ssh config file “vim ~/.ssh/config”, and paste the below lines.
Host jumpBox
HostName jumpBox.host-name.com
User pavan.ceemala
#### My Endpoints
LocalForward 127.0.0.1:9876 api.pkc.com:80
LocalForward 127.0.0.1:9877 front.pkc.com:80

3. Run this command from the console, and provide your credentials which you use to access the

ssh jumpBox

4. Now we can access any URL which is configured in step 4 via postman, browser, or DB via your DB client

eg:

To access api.pkc.com:80, using postman, enter http://localhost:9876 in text field and modify Host header to “api.pkc.com“, and hit send, you should see the api response.

If you would like to use Chrome browser, you can install ModHeader plugin and the Host header inside the modheader plugin and access the URL.

--

--