SSH Tunneling
Introduction
Security tends to be a big concern and leaving Apache exposed to the internet can lead to general badness. Ideally you would lock down ip tables to access from a single IP but this may not work in all cases. Leaving SSH exposed is generally more secure than leaving Apache exposed. SSH can also be locked down to an unprivileged user with key only authentication making it more secure. In general people only think of the console use of SSH to access the back end of a server. SSH allows what are called tunnels so you can pass other things over this secured connection.
KEEP IN MIND THERE IS N O SUCH THING AS ABSOLUTE SECURITY. THE ONLY WAY TO BE ABSOLUTELY SECURE IS TO NEVER OWN A ELECTRONIC DEVICE
LINUX
When using any Linux/Unix terminal to SSH you can tunnel your local traffic across your SSH session.
Normal SSH Command
ssh root@203.0.113.1 |
To forward a local port through our connection to the remote system we use -L
SSH Command forwarding port 80
ssh -L 9999:localhost:80 root@203.0.113.1 |
In the above command we use -L followed by <LOCALPORT>:localhost:<REMOTEPORT> In this example once connected I can go to my web browser and type http://localhost:9999 and it will take me to port 80 on the connected server. This can be done with any port. You could use 9999:localhost:443 for ssl then connect to https://localhost:9999 to access a ssl secured page. This allows you to tunnel to any server on the connected network with a small modification. It the above examples we use localhost in our forward command to connect to the servers own ports. This can be modified to another server that machine can connect to. For example you could use 9999:192.168.0.252:80 to connect through that server to 192.168.0.252's web server on the network you are connecting to. In your local browser you would still type http://localhost:9999