hasenj blog

modifying plink to work with unison

Posted in hacking, webdev by hasen on 19/12/2008

Last time I talked about how to make unison work on windows with ssh.

Well, there was still one problem that remained unsolved, that is, password input.

I thought about the issue and figured I could hack plink’s source code to make the modifications necessary to make it work like unison expects it to.

The changes are simple:

  • make it accept -e none
  • make it print the password prompt to stderr instead of stdout

in winsoncs.h change hin and hout, around line 325:

    hout = GetStdHandle(STD_ERROR_HANDLE);

and in cmdline.c around line 438:

    //ignore "-e" option! (for unison compatibility)
    if( !strcmp(p,"-e") )

It’s not heavy tested, and frankly it’s a hack in a sense, I didn’t study plink’s source code in any kind of depth! Who knows, maybe my changes break the behavior in some (at least subtle) ways, but it works for me!

here is the result

This is not a wrapper; it’s a modified plink, and we call it ssh.exe so that it integrates with unison.


3 Responses

Subscribe to comments with RSS.

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

    Instructions for using Unison on Windows to connect to a remote Linux host without having to enter a password on the command line (for Unison scripting purposes)

    0. Install Unison from http://alan.petitepomme.net/unison/index.html.

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

    2. Add C:\Program Files\ICW\Bin and C:\Program Files\Unison (or whichever directory you installed the Unison text binary to) to the Windows PATH environment variable. Restart (logging off and back on may be sufficient).

    3. Generate an RSA key pair to allow for logging into the remote Linux host via SSH without having to specify a password. From the Windows command prompt, issue:

    $ ssh-keygen -t rsa -f %userprofile%/.ssh/id_rsa -C “your@emailaddress.com”

    (Note: ssh-keygen seems to take quite awhile to launch; give it 15-20 seconds.)

    4. Create the .ssh directory on the remote Linux machine and set its permissions appropriately. From the Windows command prompt, issue:

    $ ssh username@remote “mkdir ~/.ssh;chmod 700 ~/.ssh”

    You may receive an error, “File exists”, which you can ignore. This means that the .ssh directory already exists.

    5. Copy your public key file to the appropriate location on the remote Linux host. From the Windows command prompt, issue:

    scp /cygdrive/c/Users/[your Windows username]/.ssh/id_rsa.pub username@remote:~/.ssh/authorized_keys

    (Note: Be sure to replace [your Windows username] with your own Windows account username.)

    If you receive a “File exists” error, you will need to copy/paste the contents of %userprofile%\.ssh\id_rsa into the end of the ~/.ssh/authorized_keys file on the remote Linux server.

    6. Ensure that the following lines are present in the SSH config file (usually located at /etc/ssh/sshd_config):

    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys

    (Note: on some systems, you may need to duplicate your public key file and name it authorized_keys2, and modify /etc/ssh/sshd_config to include the second file, too.)

    7. Restart the ssh daemon on the Linux machine:

    $ /etc/init.d/sshd restart

    8. Test unison on the remote Linux computer. From the Windows command prompt:

    $ ssh username@remote unison -version

    9. Test the local unison installation. From the Windows command prompt:

    $ unison -version

    (Note: If you receive “‘unison is not recognized as an internal or external command…'”, you appear not to have unison.exe in a directory that is specified in the Windows PATH variable, as detailed in Step 2.)

  2. Jake Delph said, on 03/06/2009 at 8:46 pm

    If you receive a “Too many arguments” error in Step 3, there are spaces in the destination path, and you need to quote the path, e.g.:

    $ ssh-keygen -t rsa -f “%userprofile%/.ssh/id_rsa” -C “your@emailaddress.com”

    The spaces/quotes issue also applies in Step 5. Additionally, you may need to modify the path to your Windows account profile (I used Windows Vista, so my profile is in “C:\Users”, whereas on Windows 2000/XP, it would be in “C:\Documents and Settings”). So, in Windows XP, the command would be (all an one line):

    scp “/cygdrive/c/Documents and Settings/[your Windows username]/.ssh/id_rsa.pub” username@remote:~/.ssh/authorized_keys

  3. Jonas Nyström said, on 05/07/2011 at 1:48 am

    Great post and great hack! Thank you!

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

%d bloggers like this: