Install Unison on Windows with Cygwin and Linux to Synchronize Files on multiple Servers for Simple Deployment

Deployment Simple for Servers multiple on Files Synchronize to Linux and Cygwin with Windows on Unison Install

Unison is the best program I have found to synchronize files between 

a Windows System and a Linux System. 

Unison needs ssh, So i give you the following instruction how to install ssh on Windows and Linux and how to synchronize between the two machines.

 

Install Unison on Linux System

 

Unison has to be installed on server1 and server2; since we connect from server1 to server2 using SSH, we also need the SSH packages. This can be achieved as follows:

apt-get install unison openssh-server ssh

 

Creating A Private/Public Key Pair On server1

Now we create a private/public key pair on server1

ssh-keygen -t dsa

 

Generating public/private dsa key pair.

Enter file in which to save the key (/root/.ssh/id_dsa): <-- ENTER

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): <-- ENTER

Enter same passphrase again: <-- ENTER

Your identification has been saved in /root/.ssh/id_dsa.

Your public key has been saved in /root/.ssh/id_dsa.pub.

The key fingerprint is:

1b:95:bc:4a:f4:9f:d8:ea: 24:31:0f:c9:72:d5:a7:80 root@server1.com

The key's randomart image is:

+--[ DSA 1024]----+

|                 |

|         o s     |

|        E * . .  |

|       o = o o   |

|      . S od .   |

|       + O + .   |

|        + + +    |

|         o .     |

|         .o      |

+-----------------+

root@server1:~#

 

It is important that you do not enter a passphrase otherwise the mirroring will not work without human interaction so simply hit ENTER!

Next, we copy our public key to server2

ssh-copy-id -i $HOME/.ssh/id_dsa.pub root@192.168.1.101

 

The authenticity of host '192.168.1.101 (192.168.1.101)' can't be established.

RSA key fingerprint is
11:95:bc:4a:f48:ea: 24:31:95:56:62:4e.

Are you sure you want to continue connecting (yes/no)? <-- yes (you will see this only if this is the first time you connect to server2) 

Warning: Permanently added '192.168.1.101' (RSA) to the list of known hosts.

root@192.168.0.101's password: <-- server2 root password

Now try logging into the machine, with "ssh 'root@192.168.1.101'", and check in:

 

  .ssh/authorized_keys

 

to make sure we haven't added extra keys that you weren't expecting.

 

Install Unison on Windows System

 

Cygwin

1. Download cygwin (http://cygwin.com/setup.exe).

2. Create a directory in c:\ call it "cygwin" and put setup.exe in there.(run that as admin)

3. Search for openssh and click on skip to change it to newest version.

4. On OpenSSH make sure under B the box it checked.

5. Search for unison and click on newest version.

6. On unison make sure under B the box it checked.

7. Click the start button, right click on Computer and select properties, click Advanced system setting, on the advanched tab click Environment Variables.

8. Under System Variables find "Path" and edit.

9. In Variable value add to the end.(No quotes just whats in them) ";c:\cygwin\bin"

10. On your desktop right click and run as administrator Cygwin Terminal.

11. cd ..

11. Run these commands in the terminal. One at a time

mkgroup -l > /etc/group

mkpasswd -l > /etc/passwd 

chmod +r  /etc/passwd 

chmod u+w /etc/passwd

chmod +r  /etc/group

chmod u+w /etc/group

chmod  755  /var  

touch /var/log/sshd.log

chmod 664 /var/log/sshd.log

 

12. Now run "ssh-host-config" when you reach the question

" Enter the value of CYGWIN for the daemon:" enter "ntsec tty".Answer all questions 

with yes except "This script plans to use cyg_server, Do you want to use a different name?" enter yes and put the 

name as "sshd".Then make up a password for that account.

 

13. Run "cyglsa-config". Anwser Yes to the question.

14.VERY IMPORTANT STEP REBOOT YOUR COMPUTER.

15. Open a Windows command prompt as administrator and run "cd C:\cygwin\bin"

16. Run "ash" then "/usr/bin/rebaseall"

17. Open your cygwin terminal as admin and type these commands.

     chown system /etc/ssh*

     chown system /var/empty

18. In the start menu type services.msc and find the "CYGWIN sshd" right click and properties.

On the log ON tab click "Local System Account" and check the box underneath.

Big Thanks to http://pigtail.net/LRP/printsrv/cygwin-sshd.html

 

 

Running Unison

 

We can now run Unison for the first time to synchronize the /var/www directory on both servers. On server1 run:

unison /var/www ssh://192.168.1.101//var/www

 

Synchronize between Linux machines:

 

Of course, we don't want to run Unison interactively, therefore we can create a preferences file (/root/.unison/default.prf) that contains all settings that we otherwise would have to specify on the command line:

edit the file and insert following:

# Roots of the synchronization

root = /var/www

root = ssh://192.168.1.101//var/www

 

Synchronize between Linux and Windows machines:

# Roots of the synchronization

root = /var/www

root = ssh://user@192.168.1.101///cygdrive/c/public/var/www

 

to run it with the profil, do following:

unison

or you have another file for example server1.prf so start it with

unison server1

 

Firewall

don't forget to open the port 22 for ssh in local subnet.

 

That's it!



Saving the comment

Add comment

Required Please choose another name

biuquote
  • Comment
  • Preview
Loading

192.168.15.197