The Daily Build

Icon

Software Development, version 3.0

Use Local SSH Forwarding to Reduce the Number of Manual Hops

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

Local port forwarding is the same as remote port forwarding but works in the opposite direction. An example is the clearest way to explain.

Assuming you’ve done the steps in the previous posts, then at home you can run “ssh -L 4022:localhost:4022 me@cloud.example.com”. This listens on TCP port 4022 on your home machine. Any connections there will be forwarded through the ssh connection to port 4022 on cloud… which, as we recall, gets forwarded to port 22 (ssh) at work. If you leave this connection open, you can run “ssh -p 4022 localhost” on your home machine and it will connect to work in just one hop. This means that you can use scp to copy files from home to work or vice versa. For example, “scp -P 4022 localhost:/tmp/foo.txt ~/foo.txt” will copy a file from work to home. (Note: scp needs capital “-P” to give the port. I got it wrong the first time.)

Share and Enjoy:
  • del.icio.us
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Google Bookmarks
  • Twitter
  • FriendFeed
  • Posterous
  • email

Like this post? Get updates from my feed.

Related posts:

  1. How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels Ssh tunneling can be a bit mind bending at first,...
  2. Open an SSH Tunnel in Four Seconds or Less As I mentioned in a previous post on ssh configuration,...
  3. Use SSH to Forward Multiple Protocols to Multiple Machines Let's say you have a half-dozen machines at work you...
  4. How to Tell SSH Who You Are Do you log in to several servers with different usernames...
  5. Python Exception Handling: Cleanup and Reraise I’ve had this code around for a while and...

Category: ssh

Tagged: , , ,

2 Responses

  1. kevin clark says:

    Suggestion: for scp, you want to use a capital ‘P’, as in “-P”.

  2. Thanks Kevin. I fixed it and added a note.

Leave a Reply

Related Posts

Related posts:

  1. How to Use SSH Remote Port Forwarding to Set Up Secure Tunnels Ssh tunneling can be a bit mind bending at first,...
  2. Open an SSH Tunnel in Four Seconds or Less As I mentioned in a previous post on ssh configuration,...
  3. Use SSH to Forward Multiple Protocols to Multiple Machines Let's say you have a half-dozen machines at work you...
  4. How to Tell SSH Who You Are Do you log in to several servers with different usernames...
  5. Python Exception Handling: Cleanup and Reraise I’ve had this code around for a while and...