hasenj blog

unison on windows (ssh on windows)

Posted in webdev by hasenj on 12/11/2008

[Update: this post discusses some outdated techniques, please see this newer post for a better technique to use ssh with unison on windows]

I’m running windows vista on a laptop, and need to synchronize files with a linux server (for a web development project). After googling for a while, I found two options: rsync and unison. rsync requires cygwin, and it’s for (uni-directional) mirroring. unison on the other hand does not require cygwin, and is designed for (bi-directional) synchronization. so I chose unison.

Unison seems easy enough to use, check out the tutorial on its manual page.

but I quickly discovered that it doesn’t really work on windows out of the box: it needs “ssh”, or an ssh-like tool to be present on the machine, and guess what, ssh requires cygwin!

Now, there’s “plink” which behaves pretty much like ssh, except for some subtle differences, but these “subtle” differences render it unusable with unison. The problem is that unison sends some command-line options to ssh that plink can’t understand.

I found this discussion page on google, and a solution is offered in the form of a bat file that removes the extra command-line arguments before passing the rest to plink

http://twiki.org/p/pub/Codev/UnisonKeySetup/ssh2plink.bat

So you can save this file somewhere and use the -sshcmd option to make unison use this file as if it was “ssh”.

A problem arises when you connect to the server and you are prompted to enter your password: unison chocks and says “the ssh server is responding with something that I don’t understand, so I’ll quit”!! You’d expect a program that’s designed to connect to ssh servers and sync files with them to be smart enough to handle the password prompt; but then again, we’re using plink, where as unison expects “ssh”, and I guess this is also one of the “subtle” differences between ssh and plink.

so as a way around that we could pass the password on the command line using -sshargs option.
see, plink has this option “-pw password” which has the nice effect of allowing you to bypass the “password prompt”, and we can use it for this purpose. pass this to unison:

-sshargs “-pw password”

and it should do the trick (you need the quotes ..)
of course when you automate this, it raises the issue of having your password stored somewhere in a text file on your laptop; so you have to watch out and make sure no unauthorized person can read this file.

Now, if you actually google “window unison ssh”, you will see this page http://www.wischik.com/lu/programmer/unison-ssh.html

which provides a nice tool (conveniently named “ssh.exe”) that you can copy to a folder that’s included in your PATH environment variable, but it still suffers from a problem with the password prompt: the prmopt is broken; it doesn’t work (at least on my vista laptop), as soon as you type the first character, it presses enter for you and prompts you to enter the password again because the password that you just entered is incorrect :) (maybe this only happens in vista, but it happens for me, and that’s what matters).

Now, there’s another dependency that you will probably need: diff, as unison uses it (optionally) to show the differences between files. So you might consider downloading it if you don’t already have it.

About these ads
Tagged with: , , , ,

2 Responses

Subscribe to comments with RSS.

  1. Jake Delph said, on 17/05/2009 at 11:09 pm

    Why not use SSHWindows?

    http://sshwindows.sourceforge.net/download/

    It works just fine with Unison 2.27.57 on Windows 7 RC 1.

  2. Jake Delph said, on 18/05/2009 at 1:36 am

    In my previous reply, I was suggesting SSHWindows because it works with Unison. However, I realized that SSHWindows does not allow for private key file authentication on the remote Linux host, due to cygwin-related permissions problems on the private RSA key file (which should be stored in %userprofile%\.ssh on Windows). For this reason, Unison cannot be automated over SSH, because the remote host will not allow the key file to be used due to its unsecured permissions. See this thread for details:

    http://www.bitbenderforums.com/forums/showthread.php?postid=497426

    To work around that problem, I uninstalled SSHWindows and alternatively installed copssh from

    http://sourceforge.net/project/showfiles.php?group_id=69227&package_id=127780

    Now, if I open a Windows command prompt and do something like

    $ cd “C:\Program Files\ICW\Bin”
    $ ssh username@remote

    I am not prompted for a password. Rather, the remote Linux server accepts my private RSA key and I’m in.

    Of course, adding C:\Program Files\ICW\Bin to the Windows PATH environment variable will enable you to use ssh (and the other UNIX tools that are included in copssh’s Bin directory). A log-off or a restart will be required before the PATH change takes effect.

    I have posted fairly comprehensive instructions for using Unison on Windows to connect to a remote Linux host at the newer thread:

    http://hasenj.wordpress.com/2008/12/19/modifying-plink-to-work-with-unison/


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: