This is one of those topics that - although Corny - you often have to face and discuss in depth, especially when you start working with a new team. I refer to the procedures scp automatic synchronization between the files and / or directories on two servers, UNIX / Linux.

The logic is simple and the implementation takes less than a minute. But ... but there are many secondary aspects that encourage the adoption of this approach only in specific cases. One of these is the chasm of security leading to the complete opening to anyone who provides the private key. In short, it's late and explain the risk of harm, we see the case and a few instructions for completing the whole.

Suppose we have two servers (and A.test.com B.test.com) and want to keep an exact copy of the directory / root / test by making a `scp` to every night A.test.com B.test.com .

1. Generate a pair of private / public key on the local server A.test.com:

 
 ssh-keygen-t rsa 

When prompted for a password, do not enter anything in this way the `scp` session will take place without any authentication request. If the private key falls into the wrong hands, however, the server is definitely compromised. This is why a solution like this is good only on an intranet, between a server and a main backup, for example. And in any case a solution has to be taken only for servers that are accessed by the fewest people possible.

2. Copy the public key on the remote server B.test.com

 
 scp ~ / .ssh / id_rsa.pub root@B.test.com: ~ 

3. Add the key copied to the remote server trusted keydel B.test.com
Access to the remote server and hang the key as follows:

 
 cat ~ / id_rsa.pub>> ~ / .ssh / authorized_keys 

In the event that the directory ~ / .ssh / authorized_keys does not exist, means that it has never been any pair of keys generated for the remote server. Run the command "ssh-keygen-t rsa". For safety, you should make sure that only the user key owner can access it:

 
 chmod 600 ~ / .ssh / authorized_keys 

4. Test password-less access to A.test.com B.test.com

 
 ssh root@B.test.com 

Access is now without a request for a password.

5. Putting education scp in cron

 
 scp-r / root / test / * root@B.test.com: / root / test / 

Look no further ...