# using unison on server to sync with machine inside a network

## ad_meis

Dear Gentoo Forums,

I have the following issue. I have a laptop that I carry with me and a desktop in the office.

Whenever I go to the office daily I sync the laptop and the desktop with unison.

However it happens that I have more and more days of work out of the office, and when not in the office, it is not possible to directly sync laptop (A) to desktop (B). I have the possibility to ssh connect to a third machine, a server (C) from which I can access my office desktop, however I am granted very limited disk space on the server (I cannot use it for backup). My question is: can I sync A and B taking advantage of ssh connection with the server (but without actually saving data on the server)?

Hope this is clear. I am now familiar with using unison, but I am of course open to other solutions.

thanks for your help

----------

## VinzC

If you know which port unison uses for synchronization (if it uses just one port) you can setup an SSH tunnel at your server machine C, will act like a VPN.

----------

## jormartr

As VinzC says, use a ssh port forward (example: 2222), and unison like

unison /local/path ssh://localhost:2222//remote/path.

----------

## ad_meis

Thanks, I ll look into this. And let you know

----------

## ad_meis

I am having trouble with the correct number for the port.

Is there a way to discover what port is unison using for the synchronization?

----------

## VinzC

 *ad_meis wrote:*   

> I am having trouble with the correct number for the port.
> 
> Is there a way to discover what port is unison using for the synchronization?

 

On a *NIX machine in general I use netstat -ltaup . The -p argument will show you the process name that owns which ports in the list.

----------

## jormartr

I think it should work doing a port forward within ssh, like:

office desktop lan ip: 10.0.0.2

office server lan ip: 10.0.0.1

office server public ip: 1.2.3.4

then, from home

ssh user@1.2.3.4 -L 2222:10.0.0.2:22

unison /local/path ssh://localhost:2222//remote/path

I write this without any test, I think its a way to make it.

----------

## ad_meis

Thanks again. I cannot have it working. But it could be a mistake on my side.

The first line with the ssh connection goes fine. Troubles are with the second line. Say that username is mike on all machine, and I want to sync /home/mike on laptop and office desktop, then your last line becomes:

unison /home/mike ssh://localhost:2222//home/mike

I have tried both with "localhost" and by substituting it with what set into /etc/hosts.  

This is the error message I get

```
[/quote]Contacting server...

ssh: connect to host localhost port 2222: Connection refused

Fatal error: Lost connection with the server
```

----------

## jormartr

Take a look at some documentation or these:

http://www.debianadmin.com/howto-use-ssh-local-and-remote-port-forwarding.html

https://help.ubuntu.com/community/SSH/OpenSSH/PortForwarding

you are interested in local port forwarding.

----------

## ad_meis

Thanks again. I have read the two links, but cannot have it working yet

----------

## jormartr

Try running "ssh office_public_ip -L local_port_to_bind:local_workstation_address_on_office:office_workstation_ssh_port -v", that is, with verbose option.

and then connect to your office workstation with ssh localhost -p local_port_to_bind, and read the messages on the first command, and maybe you find something useful, like server is not forwarding ports, or something else.

----------

