Tuesday, September 29, 2015

Transfer Files through an SSH terminal on Windows such as PuTTY to/from UNIX/Linux/BSD remote host using sz and rz Zmodem commands

Have you ever wished you could transfer files through your ssh terminal window without having to run a separate sFTP-type program?  This is a pretty old-school method that must not be popular in these days, judging from how rarely it seems the "sz" and "rz" commands are even available on a system, but it's likely that you can install them.  The letters in these commands stand for "send Zmodem" and "receive Zmodem."

On a Windows client side, one could just use SecureCRT as it appears to support this by default, and using it would probably make the Windows side of this much simpler.  If both the client and server sides are non-Windows systems, that can also simplify matters.

Because SecureCRT is not free software, many people use PuTTY or one of its forks: "KiTTY" or "Le Putty."  One reason for both of these is the addition of support for Zmodem transfers.

Windows Client Side:

The KiTTY program can be found here: http://www.9bis.net/kitty/?page=ZModem
Le Putty home page: http://leputty.sourceforge.net/

In both cases there is no Windows installer, it's just a [zipped] .exe program that includes or requires the "sz.exe" and "rz.exe" executable files as well.

With both KiTTY and Le Putty the Zmodem settings are saved within the particular session profile.  With KiTTY the saved sessions/settings seem to be shared with those of PuTTY if it has also been used.*  Be sure to save your session info with your chosen Zmodem-transfer settings.

The settings for Zmodem transfers include the local folder for downloads to arrive in as well as the path and command line options for the client-side sz and rz commands, which should include the full path as well as the .exe extension.

For example, you might place your rz.exe and sz.exe files in a folder like C:\sshz, along with the KiTTY or Le PuTTY program files.  In the settings you might set your Zmodem download folder to "C:\sshz\downloads" and the command lines for sz to "C:\sshz\sz.exe" and for rz to "C:\sshz\rz.exe" respectively.
(note: it would probably be wiser to use a different directory than just C:\sshz, maybe something in your user profile or My Documents folder.  This is just an example path.)

That's about it for the Windows client side of things, though I would also note that in order to actually start a Zmodem upload from the client after the "rz" command has been used on the server, you must right-click on the terminal window's title-bar with your mouse pointer and then choose "Zmodem Upload" and select the file to be sent.  Likewise, to download a file after starting "sz" you'd need to right-click the title bar and select Zmodem Receive.

Remote host server side:

If the server already has the rz and sz (or lrz and lsz) commands installed and available, your work is done for you there.  If not, you can install them yourself from source, even if you don't have root access.  Personally I find this quite handy and nice to be able to do: building and installing software even without root access.

At the time of writing, the source tarball is available at: ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz

If you do indeed have root access and wish to install lrz and lsz on the system, there might be a package available for your distribution.  With Debian or Mint or Ubuntu, for example, you can just install it using apt-get like so:

apt-get install lrzsz

When installing from source, however, the "-prefix=$HOME" option for the ./configure command line below is necessary if operating without root access.  In the following example I do not have root access to my web hosting machine and so I did use that option.

The commands I used to install lrzsz are as follows:

cd ~
mkdir gets
cd gets
wget http://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
tar -xzvf lrzsz-0.12.20.tar.gz
cd lrzsz-0.12.20
./configure -prefix=$HOME
make
make install
find . | grep lsz

(and of course what the commands are doing is: first navigating to the user's home directory, then
creating a folder called "gets" for keeping files downloaded with wget, then entering that folder, then using wget to download the source tarball to the folder, then un-zipping the contents with tar, then entering the new folder for lrzsz, then building and installing it with configure/make/make install, then locating the binary executable file with find.)

After that I used "alias" so that when I type the commands "sz" or "rz" it will use the lsz/lrz programs, like so :

alias sz='~/gets/lrzsz-0.12.20/src/lsz '
alias rz='~/gets/lrzsz-0.12.20/src/lrz '

Those lines could be added to your .bash_profile or .bash_rc file, for example, to insure that they're aliased every time you log in.

Note that in this scenario, using "sz" on the remote host requires that you specify in the command line the file to be sent, like "sz filename" for example, whereas using "rz" doesn't require a file name to be specified.  "rz" may require the "-y" option to overwrite a file if there is already a file with the same name in the working directory.  After a transfer there may be a bit of confusing text in the console which can be clarified by pressing ENTER a couple of times to see the prompt again, or by using the "clear" command.  Using "Ctrl-C" does not abort the command after using sz or rz but it will timeout within a few minutes if the transfer is not started.

[Edit] Please Note that the permissions for transferred files may not be as expected.
I find myself using "chmod 644 filename" often after uploading files.
This point could be an important security consideration.

There are a number of command line options for both "rz" and "sz" which can change their behavior, and they can be listed by using "rz --help" or "sz --help" respectively, even if the "man pages" or the "info" command do not provide documentation.

*(Unless it's the portable KiTTY package available from portableapps, which seems to keep its own data separate and isolated from that of PuTTY.)

Links and references:

SecureCRT info: https://www.vandyke.com/products/securecrt/ssh_file_transfer.html
Kitty Zmodem-specifics: http://www.9bis.net/kitty/?page=ZModem&theme=none
Le Putty: http://leputty.sourceforge.net/
lrzsz: https://ohse.de/uwe/software/lrzsz.html
helpful page: https://waltonr.wordpress.com/2011/12/08/howto-lz-rz-function-sexy-commandline-file-transfers/
helpful page: http://sourceforge.net/p/leputty/support-requests/1/

Tuesday, September 22, 2015

Oracle VirtualBox on Debian Wheezy Installation Fail and Solution

Upon attempting to install Oracle VirtualBox on a Debian GNU/Linux system, you might run into a colorful error:

[FAIL] Starting VirtualBox kernel modules[....] No suitable module for running kernel found ... failed!

After a bit of searching I found a sort of solution to my problem which was:

      Install "module-assistant" and install VirtualBox from the "backports" repository.

While this is an official resource, it might not be the ideal solution to use a backport, which I'll come back to below with a "Second solution."  In this case I am using Debian 7 "wheezy," and the backport would be from "jessie" or "stretch."

First solution:

Run these commands to get the Module Assistant program ready:

apt-get install module-assistant

m-a prepare

I believe it was actually unnecessary to install headers with the following command, but I've included it just in case it's helpful in other situations:

apt-get install linux-headers-$(uname -r|sed 's,[^-]*-[^-]-,,')

Then to add the backports repositories to sources.list we could use a command like

nano /etc/apt/souces.list

and add the following text:

# backported
deb http://http.debian.net/debian/ wheezy-backports main contrib

Next it's time to try installing the VirtualBox package again, with:

apt-get -t wheezy-backports install virtualbox

This worked well, despite the FAIL message being displayed again just before it installed the correct kernel modules and finished successfully.  That's when I realized it was still using an older version: VirtualBox 4.3.18 instead of 5.0.2 which was the latest.

Later I realized that you can just go to the VirtualBox website and find their latest version in a neat Debian package, so I removed VirtualBox with apt-get and removed the backports part of sources.list

Second Solution:

Details were found at:

 https://www.virtualbox.org/wiki/Linux_Downloads

In addition to having the dkms package installed, installing VirtualBox in this way requires adding a line to sources.list for installing directly from Oracle, such as:

#Oracle VirtualBox
deb http://download.virtualbox.org/virtualbox/debian wheezy contrib

It also requires installing key for apt-secure, as described on their page, like so:

wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

Even after all that, in my case there was still a warning about the source being unverifiable but then it was easy to install virtualbox 5 (actually 5.0.2, at the time) with the simple commands:

apt-get update
apt-get install VirtualBox-5.0

And it was a breeze, worked like a charm.

Compared to using a backport of an older version of VirtualBox, this method may be preferable.

It's probably safe to assume that this has been a problem for more people than just you and I, and recently I'd noticed that there is actually an entire distribution based primarily on the combination of VirtualBox and Debian.  It's called Robolinux.

I wish I'd recorded links to the other sites that were helpful to me with this so I could credit them here, but this should be enough information to get around the error message or to get the application installed, anyway.