Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I recently set up a remote server, which I have running the bare minimums currently. I set up OpenSSH and can access the machine through one of my domain names (using an A-type DNS record). I also have a web server running on the machine, but all ports except SSH are blocked at the gateway.

While in the future I plan to open port 80, for now as I'm in "development" mode, and I would like to disallow any outside access or traffic to the web server through port 80 (or over the HTTP protocol for that matter). Right now, the only way to access the machine externally is through an SSH connection.

Now, I was wondering: how can I redirect the local HTTP server traffic through SSH so I can access my web server locally? Can this be done even if I have port 80 firewalled at the router/gateway?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

yes, using ssh port forwarding.

ssh -L 80:localhost:80 name-of-remote-system

This will send any browser connection to port 80 on your local machine over ssh to the remote machine. Once there, it will continue to localhost (the machine you used ssh to connect to), port 80.

share|improve this answer
    
Awesome, thank you! I had heard of SSH tunneling before, but hadn't used it since now. Note that I did have to use sudo to run this command. –  Breakthrough Jul 19 '13 at 14:22
    
Actually, as a small follow-up to my previous comment; running the command without sudo will cause the error Privelaged ports can only be forwarded by root. to appear. However, once I prepended sudo to the SSH command, I noticed my RSA-key credentials were being rejected. Note that unless your sudo user shares the same SSH keys, you will need to specify the path to your current keyfile using the -i argument (e.g. append -i /home/YOUR_USERNAME/.ssh/id_rsa to the end of the command). –  Breakthrough Aug 24 '13 at 18:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.