Open an SSH Tunnel in Four Seconds or Less

(This is part four in a series of posts on ssh.)

As I mentioned in a previous post on ssh configuration, your config file can specify a variety settings for each server.

In fact, the Hosts you use don't even have to exist! (The HostName is the important part.) Consider the following snippet in your ~/.ssh/config.

#
Host work
  HostName localhost
  User myworklogin
  IdentityFile ~/.ssh/id_dsa
  Port 4022
  RSAAuthentication yes
  PubkeyAuthentication yes
  LocalForward 4022 localhost:4022

I'm going to assume remote forwarding is set up and the connection is open from work to cloud as described in this post on remote forwarding; and you've got local forwarding set up from home to cloud as described in this post on local port forwarding.

Now you can do ssh work from your home pc, and it will automatically log you into your work pc with the right credentials using the tunnel on cloud.example.com. And scp simplifies to scp work:/tmp/foo.txt ~/foo.txt -- you don't have to remember the forwarded port numbers.

Typing ssh work is nine keystrokes (eight letters plus enter). If you can type 40 wpm, that's 200 keystrokes per minute, or 3.33 keystrokes per second, which means you can open the tunnel in four seconds!

If you add alias ssw='ssh work' to your ~/.bashrc, you're down to four keystrokes.

Posted on 2009-12-03 by brian in ssh .
Comments on this post are closed. If you have something to share, please send me email.