start a tunnel from some machine's port 80 to your local post 2001

ssh -N -L2001:localhost:80 somemachine
now you can acces the website by going to http://localhost:2001/

2009-02-05 09:13:23

What Others Think

What are the caveats for this working?
DannoHung · 763 weeks and 3 days ago
none, as far as i know. i use this to access a customers intraweb application. this way the customer only needs to open up port 22 (ssh) in the firewall for just one ip address of some machine in your local lan (your hub machine). this way you can hop for your laptop to that local machine to the customers machine. as secure as it get's while still being relatively easy to use. no tokenstuff needed (i hate tokens and the 'supposed better' security).
mischamolhoek · 763 weeks and 2 days ago
Some web applications will get upset if you supply a port when they're not expecting it, or will break if they expect to be able to do redirects or URL rewriting. But in general, this will work. Everyone in my company uses this every single day!
semanticist · 761 weeks and 4 days ago
ssh -D 9000 somemachine Sets up local port 9000 as a SOCKS 5 proxy via somemachine
rae · 761 weeks and 3 days ago
a little more details, for example, in the case of an email client on a laptop, pointing to localhost:8025 for SMTP services, and localhost:8110 for POP3 services associated with a Comcast account, w/out traversing ?foreign? networks with clear text credentials, looks like: ssh -f -N -L my_home_machine -L my_home_machine then, when changing locations: ps aux |grep ssh |grep -v grep |awk ?{print $2}? |xargs kill -9 and even better - setup public/private keys and you could use "-i ~/.ssh/public_key" as ssh parameter, to avoid password prompt ==> then could have everything in a shell script
netfortius · 759 weeks and 5 days ago
The params explaination: * -f tells ssh to go into the background (daemonize). * -N tells ssh that you don't want to run a remote command. That is, you only want to forward ports. * -q tells ssh to be quiet * -L specifies the port forwarding If you want use one of the reserved ports (i.e., under 1023), you will have to run as root (using sudo). Also if you want to connect to server behind the DMZ, you can use a intermediate. This is useful where your have your local machine outside a firewall; a visible machine on the DMZ; and a third machine invisible to the outside. ssh -f -N -q -L 80:
starchox · 758 weeks and 1 day ago
You can also allow access to the tunnel from incoming connections besides which is the default when not stipulated. eg ssh -f -N -L me@remote This allows on any net interface or ssh -f -N -L me@remote This allows any machine that can access your interface access to the tunnel. This is not considering firewalls.
DaveQB · 750 weeks and 3 days ago
nice; this line is also very lazy/handy; default ssh tunnel plus recovers automatically after failure. do not forget the sleep! while :; do ssh cp@ -L8081:localhost:80 -N -v -g ; sleep 100; done
cp · 623 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: