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/

221
2009-02-05 09:13:23
ssh

What Others Think

What are the caveats for this working?
DannoHung · 493 weeks 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 · 493 weeks 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 · 491 weeks and 1 day ago
ssh -D 9000 somemachine Sets up local port 9000 as a SOCKS 5 proxy via somemachine
rae · 491 weeks 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 8025:smtp.comcast.net:25 my_home_machine -L 8110:mail.comcast.net:110 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 · 489 weeks and 3 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:192.168.1.69:80 username@dmz.example.com
starchox · 487 weeks and 6 days ago
You can also allow access to the tunnel from incoming connections besides 127.0.0.1 which is the default when not stipulated. eg ssh -f -N -L 0.0.0.0:8080:google.com:80 me@remote This allows on any net interface or ssh -f -N -L 10.1.1.120:8080:google.com:80 me@remote This allows any machine that can access your 10.1.1.120 interface access to the tunnel. This is not considering firewalls.
DaveQB · 480 weeks and 1 day 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@192.168.1.19 -L8081:localhost:80 -N -v -g ; sleep 100; done
cp · 353 weeks and 3 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: