13. October 2010
05-16-11 Updated and polished.
In the previous article we established an SSH session with KiTTY. However to take full advantage of Cygwin and SSH it's equally important that your Windows client can connect with Cygwin's ssh.
As Pageant handles authentication for KiTTY, so ssh-agent authenticates for ssh.exe.
But we're on Windows! We like KiTTY, and Pageant has a nice interface, it should be all we need.
Charade is an ssh-agent in Cygwin that proxies requests to Pageant.
Client instructions (Windows-centric variation on keychain)
- Install Cygwin and hstart and configure environment variables on the client as done previously on the server.
- Compile Download charade.exe
- Drop it in C:\cygwin\bin
- Add another program start action to our Pageant entry in Task Scheduler.
Program: hstart Arguments: /noconsole "bash -c "charade > ~/.ssh-agent""
Move this entry up, before Pageant's start action.
- Append source ~/.ssh-agent to the end of C:\cygwin\home\<User>\.bash_profile
- Run task, launch local Cygwin shell, connect to your server: ssh <hostname>. Hooray!
With charade operational, we can use rsync and Unison over SSH. Awesome!
Remember when we exported our private key in OpenSSH format (no file extension)? That's the one ssh.exe requires.
Here's an example bash script for pushing changes over a LAN with rsync that handles spaces in filenames.
# escape spaces in file paths
# (the escapes won't be visible if you echo... you'd need to triple escape... which we don't want)
src="echo $src | sed 's/ /\\ /g'"
if [ $# = 2 ]
dest="echo $dest | sed 's/ /\\ /g'"
# -a, archival mode, does:
# -r (recursive)
# -l (copy symlinks as symlinks)
# -p (preserive permissions)
# -t (preserve modification times)
# -g (preserve group)
# -o (preserve owner)
# -D (preserve device & special files)
# -v, verbose
# --delete, delete extraneous files from destination dirs (DANGEROUS)
# --rsh, the remote shell to use
# -z, compress file data during the transfer
# -a, disables agent forwarding
# -x, disables x11 forwarding
# -c, set the cipher specification (blowfish being the quickest)
rsync -s -av --delete --rsh="ssh -ax -c blowfish" "$src" $receiver:"$dest"
#rsync -s -avz --delete --rsh="ssh -ax" "$src" $receiver:"$dest"
I call the script from within my text editor like this: cmd /c bash ~/push.sh Chris-Laptop 'C:\abc\some_source_dir' 'C:\some_dest_dir'
(or 'C:\abc\source_dir\' 'C:\abc\dest_dir\', or just a single 'C:\abc\source_dest\' if the path is equivalent at the destination.)
It's important to understand the distinction of a trailing slash on the source folder with rsync (especially with --delete). Back up your data before experimenting.
More to come!