Home notes to future self SSH playground

SSH playground

by Tomasz Jarosik

SSH is a secure shell which is very useful when we want to use remote servers. We can connect to host_a with simple command:

ssh host_a

What if there are proxies or firewalls between your local host (B) and the remote host (A)? SSH can be used in many scenarios. Imagine we want to connect to Android device, which exposes port 5554 to host A. But firewall on server A only allows outgoing connections, so it’s not possible to connect from server B to server A directly. To workaround this limitation and connect from host B to host A, we first have to create a ssh tunnel which we can use for communication between A and B. Let’s run this command on host A:

ssh host_b -p 2200 -R 2222:localhost:2200

ssh-fun-1
And now on host_b, when we invoke command:

ssh localhost -p 2222

we will be connected (through reverse tunnel) to host_a
Another useful thing to know is ~/.ssh/config where we can define our hosts:

Host host_b
HostName dev.example.com
Port 2200
User tjarosik

Network configuration might be even more complex when there are proxies and strict firewall rules. Let’s assume that we only have HTTP proxy to access the Internet, and everything else is blocked. There is still an option to connect to a remote server through ssh. We can’t just create a simple ssh tunnel, but we can use a corkscrew app, which enables us to create a tunnel over HTTP. All we need is a command in our ~/.ssh/config

ProxyCommand /usr/local/bin/corkscrew your.http.proxy.com 80 %h %p

Links:
https://daniel.haxx.se/docs/sshproxy.html
Black magic of SSH
https://hobo.house/2016/06/20/fun-and-profit-with-reverse-ssh-tunnels-and-autossh/
http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
http://agroman.net/corkscrew/

0 comment

You may also like

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More