Alright, if you want to sync two computers you will need to enable sftp.  On a Mac this is easy.  Open system preferences, sharing and enable Remote Login.  This enables ssh on your mac on port 22.  If you have two machines using the same router each machine will need to have a different port. On mac you need to open /System/Library/LaunchDaemons/ssh.plist and change serviceName and bounjour string from ssh to the desired port. I use 22 on my desktop and 26 on my laptop. Here is a list of standard ports.

Now that ssh is enabled on both computers you need to know how to find it on the internet.  The process isnt hard and can be done for free.  The process will start with the host domain name in a nice human readable format (www.remoteHost.com), but this is no good for a computer, it likes numbers.  So using DDNS it can translate the human readable domain name to the actual ip address.  I use no-ip’s free service and run its dynamic updater on each of my machines.  This will get us to the remote router, but now the router needs to know what computer to send the request to as there usually are many devices connected to any given router.  Using port forwarding the router can be configured to forward any given port to a given computer.  We will be using sftp (ssh) which is by default on port 22 but this can can be specified.  Therefore the router will need to forward any port 22 requests to the “remote” computer illustrated below.  This is done differently depending on your router.


Now that we know how to find the remote destination we need to do this securely.  By using rsync with the -e option we can specify the use of a secure shell (SSH).  This is great but we want to do it without having to enter the password every time we want to transfer data.  To get around this we will first have to generate a set of authentication keys using ssh-keygen.  Open a terminal and enter the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cd ~/.ssh/
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/*****/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/*****/.ssh/.
Your public key has been saved in is_rsa.pub.
The key fingerprint is:
sd:34:56:4j:56:hg:45:fg:45:4g:5h:42:df:9c:f3:dc
The key's randomart image is:
+--[ RSA 2048]----+
|        . o + ..o|
|     . o o . o o.|
|       o + o . o |
|       . o . o   |
|      . . S . .  |
|       o . +.    |
|       0 . o+    |
|       . .=      |
|        E        |
+-----------------+

Leave the passphrase blank. This will generate a keypair (private and public). Leave the private key in the .ssh folder and copy the public key contents into the authorized_users file in the remote .ssh folder. For example enter the following in the terminal:

1
2
3
4
5
$ rsync ~/.ssh/id_rsa.pub user@www.remoteHost.com:.ssh/id_rsa.pub
$ ssh user@www.remoteHost.com
password:********
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ exit

You also may need to adjust the permissions to 600 if you have problems. Now you should be able to ssh into the remote computer without entering a password. Authentication is done by matching the private key with the public key automatically. Do not share the private key!

next page—>


Be Sociable, Share!