Can I access a remote web server over an SSH connection?

8

1

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?

Breakthrough

Posted 2013-07-19T14:00:04.817

Reputation: 32 927

Answers

11

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.

BostonDriver

Posted 2013-07-19T14:00:04.817

Reputation: 452

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 – 2013-07-19T14:22:47.537

2Actually, 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 – 2013-08-24T18:22:51.640