How to forward local port 80 to another machine?

I want to port 127:0.0.1:80 to the other machine via SSH, how can I do that? I tried adding -R 8000:localhost:80, but it doesn't work. By the way, PHP is also installed on localhost, maybe that's why?


Solution 1:

Only root can bind ports numbered under 1024.

The cleanest way is just to use local port 8000:

ssh -R 8000:localhost:8000 otherhost

Alternatively,

sudo ssh -R 8000:localhost:80 me@otherhost

(It's really better not to run this as root for the sake of security - just use another port.)

If you must use root, and you're using ssh private-key authentication, you may need to tell it which identity file to use. For example

sudo ssh -i ~/.ssh/id_dsa -R 8000:localhost:80 me@otherhost

Solution 2:

Judging from what you've just said in chat, this will let you access the server's port 80, from localhost:8080 (you'd need to run this as root to get it on localhost:80, which I don't advise if you can avoid it).

ssh -L 8080:localhost:80 host