Friday, November 12, 2010

Pop Quiz Hot Shot - ssh

You have ssh'ed into a host via three others and just noticed a file(s) you would like on the laptop you started all this merriment from, what do you do? Of course you don't have a control connection or tunnelling already setup because its a "once off" multi hop connection.

A solution that is not quite as widely known as I'd thought is to use the sz and rz pair. Hurrah the zmodem programs are still just as useful today as they were in the years of yore. The snag is that your local terminal needs to have some knowledge of this, konsole works nicely and will pop up a dialog asking where to save files "sent" to it. So doing ssh server; date >/tmp/df; sz /tmp/df will result in a dialog appearing on your local display asking where to save the df file to. Note that this works over multiple intermediate ssh hops. Just perfect for when you have routed your way into a protected network via 4 hops and find out that /etc/foo.conf which is 8kb would be *really* nice to have on the laptop.

This is packaged as lrzsz for Fedora and I've made an lszrz tarball available in my n900 repository. Let the zmodem goodness rain down...

8 comments:

Troy Unrau said...

Oh man does that ever take me back :) I was using zmodem for years before KDE was even announced :) Now we just need a post about FIDOnet :P

vivo said...

oh man shoulda had know this sooner, something like 15 years sooner :)

toddrme2178 said...

This sounds wonderful, but I am not exactly clear on how to use it. Could you provide step by step instructions, or better yet a screencast, explaining exactly how to do this?

Richard Hartmann said...

Please for the love of $deity don't create a screencast. Or if you do, add a simple text snippet on what to do. screencasts are, imo, a waste of time & bandwidth 99% of the time and especially for something this simple.

The below does not work for me:

konsole #with zsh, not bash
ssh $remote #again, with zsh, not bash
sz foo

monkeyiq said...

heh, I was wondering what I could "add" to the screencast that was not in the second paragraph of the original post.

It would be interesting to see if it is konsole or zsh causing issues there.

$ konsole --version
Qt: 4.6.3
KDE Development Platform: 4.5.2 (KDE 4.5.2)
Konsole: 2.5.2

fozzy said...

There's actually a fair simpler way of transferring files across multiple hops.

Whilst it can be done on the command line, it's far easier to set it up in your ~/.ssh/config file. Here's a sample to get a file off host C to A via B:

Host C
User fred # If you're user bob on A.
ProxyCommand ssh -T -e none B nc -w 120 %h %p.

Then on host A you can simply go:

scp C:filename .

And, via the config file, it will figure out that to get to C it must establish a connection through B, this all happens transparently to you when you do the scp command.

The entry you put on the ProxyCommand is the host BEFORE the one you're connecting to. So if you're trying to get to A->B->C->D->E, then the ProxyCommand would would specify host D. (You'd also need another block for how to get to D - via C, and a block for C -via B).

And if you have a number of hosts all called a similar name, say: server1, server2, server3, which you have to jump through serverJ to get to, you can have a config entry like:

Host server*
ProxyCommand ssh -T -e none serverJ nc -w 120 %h %p.

The only thing this technique relies on is netcat/nc, which is usually standard on most linux systems.

Rafi said...

zssh: http://zssh.sourceforge.net/

For those of us who don't use konsole. After you run sz on the far end, just hit ctrl-space and run rz. It lets you run arbitrary commands, so its also conevient for pushing file to the remote machine.

Kevin L said...

Unless started with 'ssh -e none', the zmodem upload/download might fail if '~' characters are in the file somewhere.

Also, several other ssh clients are available that support zmodem: Qodem, SyncTERM, and Le Putty are open-source; ZOC is prioprietary (but a very good bargain), and Kermit is proprietary (Kermit95, but also a very good bargain), zero-cost (ckermit), or fully open-source (gkermit).

Finally, for file transfer over ssh that needs to get a little more complex -- such as needing to frequently do uploads and downloads, or integrating with scripts -- kermit is an excellent choice.