Tags:
syndication1Add my vote for this tag create new tag
, view all tags

Or how to get Unison to talk through PuTTY plink

*For people arriving from Unison FAQ:
* This site is powered by TWiki, a flexible, powerful, and easy to use enterprise collaboration platform. TWiki is a Structured Wiki, typically used to run a project development space, a document management system, a knowledge base, or any other groupware tool, on an intranet or on the internet.

MartinCleaver wrote on unison-users:

> Does anyone here use plink (see below) with Windows XP Unison? I am
> trying to avoid dependencies on cygwin. What setup/flags do you use?

Short answer:

Create shared SSH PuTTY (Windows) - SSH (Unix) key

  1. Install PuTTY and add the folder to the PATH environment variable.
  2. Generate OpenSSH keys with puttygen.
    • I left the config at SSH2 RSA.
  • I then added a private passkey phrase
  • I saved the private key in "c:\documents and settings\Martin Cleaver\PuttyPrivateKey.ppk"
    • For some reason it did not ask for an extension but I did this to match the instructions below
  • I started pagent
    • A icon appeared in the bar next to the clock
    • I right clicked this, did add key and picked my PuttyPrivateKey.ppk
    • Putty confirmed that it had loaded this.
  1. Back In puttygen, copy and paste the generated public key and append it to $HOME/.ssh/authorized_keys on the server. This will be a one-line entry as required by OpenSSH.
  2. chmod og-w $HOME/.ssh/authorized_keys

Notes

You can get a copy of your public key at any time;
  1. reload puttygen, pick the private key and enter your password.

To keep PuTTY's pageant running, start it from the Start Menu with the private key as parameter:

pageant.exe "D:\somefolder\putty-key-jerry.ppk"

Create a launcher script

Put this:

@plink mrjc.com -i "c:\Documents and Settings\Martin Cleaver\PuttyPrivateKey.ppk" -l mrjc -ssh unison -server unison -server -contactquietly

into a separate file, called plink-mrjc.bat.

and invoke thusly:

C:\moreprgs\unison>unison.exe c:\moreprgs\indigoperl\apache\TWiki\data\Sandbox ssh://mrjc.com/home/mrjc/cairotwiki.mrjc.com/twiki/data/Sandbox -sshcmd plink-mrjc.bat

In my opinion this launcher script should be completely unnecessary.

Alternate Script

Modified version, suggested by CameronDavidson - 02 Sep 2007

An intervening batch file is basically essential (Unison 2.27.29) because unison calls the ssh executable with options not understood by plink.exe. Specifically, the -e none option is expected.

I use the following batch file: http://www.twiki.org/p/pub/Codev/UnisonKeySetup/ssh2plink.bat

Usage:

  1. download and place it in the same folder as the Unison executable file
  2. edit the batch file to indicate where the plink.exe file is located.
  3. add the following line to my relevant profiles: sshcmd = ssh2plink.bat

The batch script should be reasonably robust to changes in the way Unison expects to call ssh. However, it does not refer to any private key files, because I always use pageant as my key agent, and the keys are preloaded.


History

The following notes are for perspective. If you feel I omitted anything important from the stuff below, feel free to do the wiki thing.

T E Schmitz kindly replied in http://groups.yahoo.com/group/unison-users/message/4303:

I am using Unison with PuTTY, albeit on Win2K. But that shouldn't make a difference for the set-up.

I set it up to synchronize with our local Linux server. I set PuTTY up with OpenSSH keys so I don't have to key in user/password every time. For this to work you need to start PuTTY's pageant.exe at start-up.

Set up SSH with PuTTY

Install PuTTY and add the folder to the PATH environment variable. Generate OpenSSH keys with puttygen: do not create the public key by using the button provided. Instead, cut and paste the generated key and append it to $HOME/.ssh/authorized_keys on the server. This will create a one-line entry as required by OpenSSH.

To keep PuTTY's pageant running, start it from the Start Menu with the private key as parameter:

pageant.exe "D:\somefolder\putty-key-jerry.ppk"

SSH Command for Unison

Create a .bat script which calls the Plink connection tool. (Plink.exe is a command-line connection tool similar to UNIX ssh.) This script is later passed to Unison as its ssh command.

The plink command /must/ be preceded by @ to turn echoing off, or the communication between the local Windows Unison and the one on the Linux machine will fail because CRLFs (Windows linefeeds) will be sent. Note, that echo off in the batch script will not do the trick.

plink is passed a connection profile (which was previously created with puty.exe) as well as the command to be executed on the host.

@plink -ssh unison -server -contactquietly

Now you can call the local unison which in turn needs the previously created .bat script as a parameter:

unison d:\blog ssh://server//blog -sshcmd c:\plink-script.bat

-- MartinCleaver - 05 Aug 2005

* I left the config at SSH2 RSA.

  • I then added a private passkey phrase and hit "save private key"
  • I saved the key in "c:\documents and settings\Martin Cleaver\PuttyPrivateKey.ppk"
    • For some reason it did not ask for an extension but I did this to match the instructions below
  • I started pagent
    • A icon appeared in the bar next to the clock
    • I right clicked this, did add key and picked my PuttyPrivateKey.ppk
    • Putty confirmed that it had loaded this.
  • To get the public key, reload puttygen, pick the private key and enter your password.
    • Paste the public key into the .ssh/authorized_keys file on the server

C:\moreprgs\unison>plink mrjc.com -i "c:\Documents and Settings\Martin Cleaver\P uttyPrivateKey.ppk" -l mrjc

This successfully logged in (albeit with a somewhat messed up terminal setting).

-- MartinCleaver - 05 Aug 2005

In you prf file include the following: sshcmd = launcher.bat

Contents of launcher.bat plink -ssh -P 22 -2 -l "USERNAME" -pw "PASSWORD" -i "Path to putty key" server.com unison -server

You may or may not need all the options passed to plink. I tried to simply list put this one single line such that the prf file was sshcmd = plink ... (etc), however that did not work for me smile

-- hilton_kev on unison_users

Hi Tarlika, I did the putty set up (Notes about specific additional steps are on http://twiki.org/cgi-bin/view/Codev/UnisonKeySetup as bulletpoints)

then:

C:\moreprgs\unison>unisonplink.bat c:\moreprgs\indigoperl\apache\TWiki\data\Sandbox ssh://mrjc.com/home/mrjc/cairotwiki.mrjc.com/twiki/data/Sandbox -sshcmd unisonplink.bat

plink: unknown option "-server" plink: unknown option "-contactquietly"

C:\moreprgs\unison>more unisonplink.bat @plink -ssh unison -server -contactquietly

C:\moreprgs\unison>unison.exe -server Unison 2.12.15

C:\moreprgs\unison>plink mrjc.com login as: mrjc Password: ^C

Pagent is running.

Special thanks for any help. (This is so frustrating).

Cheers, -- MartinCleaver

Something wrong with your script as you seem to be passing -server and -contactquietly to plink rather than to unison.

Do this in little steps: First of all just run plink, which should log you on to the server:

@plink -ssh

Once this logs you in, you know that the plink set-up is working.

Then run the plink-script.bat, which should read

@plink -ssh unison -server -contactquietly

That talks to the unison on the host. The result is a response from the host's unison:

"Unison 2.9.1"

You need to abort this with Ctrl-C

Once that is all working you try

unison d:\blog ssh://server//blog -sshcmd c:\plink-script.bat

-- T E Schmitz

>> C:\moreprgs\unison>unisonplink.bat
>> c:\moreprgs\indigoperl\apache\TWiki\data\Sandbox ssh://mrjc.com/home/mrjc/cairotwiki.mrjc.com/twiki/data/Sandbox
>> -sshcmd unisonplink.bat
>> plink: unknown option "-server"
>> plink: unknown option "-contactquietly"
>
>Something wrong with your script as you seem to be passing -server and
>-contactquietly to plink rather than to unison.
>
>
>Do this in little steps:
>First of all just run plink, which should log you on to the server:
>
>@plink -ssh
>
>
C:\moreprgs\unison>plink -ssh "c:\Documents and Settings\Martin Cleaver\PuttyPrivateKey.ppk" Unable to open connection: Host does not exist

I assume you meant I supposed to specify the host as well... certainly puttygen did not ask me to associate a host with the key when I generated it.

C:\moreprgs\unison>plink mrjc.com -i "c:\Documents and Settings\Martin Cleaver\PuttyPrivateKey.ppk" -l mrjc Using username "mrjc". Last login: Fri Aug 5 07:23:03 2005 from *.cpe.net.cable.rogers.com on NODEVssh Linux ... Mon Feb 7 13:23:30 PST 2005 i686 unknown

Now I can do:

C:\moreprgs\unison>plink mrjc.com -i "c:\Documents and Settings\Martin Cleaver\PuttyPrivateKey.ppk" -l mrjc -ssh unison -server

Which of course means that the following, in theory, should work:

C:\moreprgs\unison>unison.exe c:\moreprgs\indigoperl\apache\TWiki\data\Sandbox s sh://mrjc.com/home/mrjc/cairotwiki.mrjc.com/twiki/data/Sandbox -sshcmd plink mrj c.com -i "c:\Documents and Settings\Martin Cleaver\PuttyPrivateKey.ppk" -l mrjc -ssh unison -server

Not so, as this problem is caused by the Windows shell passing all the parameters to unison, including those due for ssh.

We finally get to the answer

So, we split this part:

@plink mrjc.com -i "c:\Documents and Settings\Martin Cleaver\PuttyPrivateKey.ppk" -l mrjc -ssh unison -server unison -server -contactquietly

into a separate file, called plink-mrjc.bat.

and call that instead:

C:\moreprgs\unison>unison.exe c:\moreprgs\indigoperl\apache\TWiki\data\Sandbox ssh://mrjc.com/home/mrjc/cairotwiki.mrjc.com/twiki/data/Sandbox -sshcmd plink-mrjc.bat

Success! (of a sorts)

Versioning problems

Received unexpected header from the server: expected "Unison 2.12.15\n" but received "Unison 2.9.1\n\000\000\000\000", which differs at "Unison 2.9". This can happen because you have different versions of Unison installed on the client and server machines, or because your connection is failing and somebody is printing an error message, or because your remote login shell is printing something itself before starting Unison.

Answer seems to be... use an older version at the client end

http://www.cis.upenn.edu/~bcpierce/unison/download/unison-contributed-binaries/windows/ has a 2.9.1 for Windows.

-- MartinCleaver - 05 Aug 2005

And now... drumroll... TWikiReplicationWithUnisonTextExample

-- MartinCleaver - 05 Aug 2005

I tried using the 2.9.1 client on my windows machine and 2.12.15 on the server, which didn't work. The error message was 'expected "Unison 2.9" but received "Unison 2.1".' which had me chasing my tail for awhile, thinking there was a much older unison on the server somewhere being used instead of mine. I upgraded the windows machine to 2.12.15 and now it works. Thanks for putting these pages together Martin (now I just have to figure out how SyncContrib works smile

-- MattWilkie - 25 Nov 2005

Topic attachments
I Attachment History Action Size Date Who Comment
MS-DOS batch filebat ssh2plink.bat r2 r1 manage 0.8 K 2007-09-02 - 15:27 CameronDavidson batch file to convert ssh command line to one for plink.exe
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2007-09-02 - CameronDavidson
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.