SSH Keys

Overview

Once configured SSH keys act as a handshake between your servers. This allows logging in without the use of a password and will form the foundation of your replication strategy.

Generate Keys

Start by running the following command on your master server to generate the SSH keys.

ssh-keygen

When prompted to "Enter file in which to save the key" simply leave the response blank and hit enter to use the default. This with create the following files private/root/.ssh/id_rsa and public/root/.ssh/id_rsa.pub.

The private key should never leave the server or be displayed.

Copy Keys

We now have the pieces needed to configure our automated login. Move the public key, /root/.ssh/id_rsa.pub, to the clone server.

ssh-copy-id root@your.clone.private.ip.address

When prompted, verify the fingerprint of the clone server as we did when logging into the master server for the first time. You will be prompted to enter a password. When prompted enter the clone server root password. This was set within the control panel post server creation. With the SSH keys added to the remote servers known_hosts you are ready to test the result. Perform the following command from the current terminal session to test.

ssh root@your.clone.private.ip.address

The shell will indicate you have logged into the clone server. Type exit to return to the master server.

Let's peel back the layers of the onion.

  • You have logged into the clone server from the master server.
  • There was no need to enter a password this time.
  • The private key, stored in id_rsa.pub has been added to the known_hosts file on the clone server.
  • This allows the clone server verify the master as a valid login source.

With automated logins configured you can continue on to set up data replication via lsyncd on the master server.