Access a server through SSH tunnel and send API requests through Postman in Windows 10 / MacOS

Indika Bandara Wijesooriya
Arimac
Published in
2 min readApr 5, 2019

You might have already know about SSH, Tunneling and also Postman and I will simply explain the situation here

You (A) have SSH access to a remote server (B), which has white listed access to a third party server (C).

You can connect (B) with SSH and through the command line, you can send requests to the server (C) with cURL.

The requirement here, send requests to the server (C) directly from your Local Machine (A) and use Postman to make things easier. Keeping things simple, I will be using a Windows 10 machine with the latest update (2019) and powershell to create the tunnel.

Step 1

Connect to your Server with SSH and create a Tunnel. If you are using a username and a password to connect,

ssh -D 5001 username@xx.xxx.xxx.xx

If you are using a public / private key

ssh -D 5001 -i .\id_rsa username@xx.xxx.xxx.xx

The ‘-D’ will open up a tunnel with dynamic port forwarding, ‘-i’ will get the private key file from its path.

If your credentials are okay, you will be connected to the server and the tunnel will be open.

Step 2

You can now change the proxy port to 8080 and try testing your APIs with postman. But it might not work due to postman’s ability of handling socks proxy. Therefore, we convert the socks proxy to http proxy using this nodejs package.

If you do not have nodejs, please install it through here.

npm install -g http-proxy-to-socks

Convert the 5001 SOCKS proxy port to 8080 HTTP proxy port.

hpts -s 127.0.0.1:5001 -p 8080

Now it will listen to requests through 8080 and direct it to 5001 with the conversion

Step 3

Setup postman proxy, go to settings, proxy and turn on the switch with the following information

Proxy server : 127.0.0.1:8080

Done! Now the postman will be able to connect to host (C) directly from your local machine (A).

--

--