Dec 2, 2009
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.)
Suggestion: for scp, you want to use a capital ‘P’, as in “-P”.
Thanks Kevin. I fixed it and added a note.