GoAdmio

sslsync

Copy the whole /etc/letsencrypt folder (certificates, private keys, and renewal settings) to another server over SSH with rsync, using the remote root password

On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also


Overview

/go/sslsync copies the SSL certificates of this server to another server, so that the other server can serve the same domains over HTTPS right away, for example when you move sites to a new server. It:

It copies everything in /etc/letsencrypt, not only the certificates of one account. That includes the private keys.

[!WARNING] Read Security first. The remote root password is written in plain text to a log file, and the connection does not verify the remote server's identity.


Quick start

/go/sslsync 203.0.113.20 'RemoteRootPassword'

Put the password in single quotes, so special characters such as $ are passed unchanged.


Syntax

/go/sslsync <remote-server> <root-password> [port]
Form Behavior
/go/sslsync <remote-server> <root-password> Copies /etc/letsencrypt over SSH port 22.
/go/sslsync <remote-server> <root-password> <port> Uses that SSH port instead.

Options

This command has no options. It takes three positional arguments.

Argument Required Default Notes
<remote-server> Yes — IP address or hostname of the destination server.
<root-password> Yes — The root password of the destination server.
[port] No 22 The SSH port of the destination server.

Nothing checks the arguments. If one is missing, the copy fails with an SSH or rsync error.

The destination server needs rsync, and it must allow root to log in over SSH with a password. See permitrootlogin. This server needs sshpass and rsync.


Output

The command prints Copying SSL to <remote-server>..., followed by the progress of rsync (the file list and a progress line for each file). There is no success message.

[!NOTE] The command always ends with exit status 0, and it always writes the marker file, even when the copy fails (for example because of a wrong password). In scripts, read the output and check the destination.

Every run is also recorded in /var/log/go/sslsync.log, including the password (see Security).

Security

[!WARNING]

  • The password is logged. The command writes all of its arguments to /var/log/go/sslsync.log, so the remote root password is stored there in plain text. It is also visible in your shell history and, while the command runs, in the process list. After use, remove the password from the log (edit or delete /var/log/go/sslsync.log), clear it from your shell history, and change the remote root password when the migration is finished.
  • The remote server is not verified. The connection turns off host key checking, so it accepts any server that answers at the address. If the address is wrong or the connection is intercepted, your private keys go to the wrong place. Check the address carefully, and run it only over a network you trust.
  • Private keys are copied. /etc/letsencrypt contains the private keys of all certificates and the keys of your Let's Encrypt account. Treat the destination server as fully trusted.

Examples

# Copy the certificates to a server on the default SSH port
/go/sslsync 203.0.113.20 'RemoteRootPassword'
# The destination server uses SSH port 2222
/go/sslsync 203.0.113.20 'RemoteRootPassword' 2222
# Afterwards, check what arrived on the destination server (run it there)
ls /etc/letsencrypt/live

Troubleshooting

Symptom Likely cause Fix
sshpass: command not found sshpass is not installed on this server. Install sshpass.
Permission denied The password is wrong, or the remote server doesn't allow root to log in with a password. Check the password, and allow it with permitrootlogin on the destination.
Connection refused or a timeout Wrong address or port, or a firewall blocks SSH. Check the address, pass the right port as the third argument, and open the port.
rsync: command not found (from the remote side) rsync is not installed on the destination server. Install rsync there.
The command looks finished, but nothing was copied The marker file is written even when the copy fails, and the exit status is always 0. Read the rsync output above, and check /etc/letsencrypt on the destination.
The password doesn't work although it is correct Special characters were changed by your shell. Put the password in single quotes.
The destination still doesn't serve HTTPS for the domains The accounts or virtual hosts don't exist there yet, or the web server hasn't reloaded. Copy the accounts first, for example with copy or serversync, then reload the web server.
Certificate renewal errors on the destination after the copy The copied renewal settings include domains that the destination server doesn't serve yet. Make sure the accounts are on the destination, and the domains point to it.
Old certificate files remain on the destination Files that exist only on the destination are not deleted. Remove them there by hand.
The password shows up in the log The command logs every argument. See Security.

Details

What it does

  1. Writes the command and all its arguments to /var/log/go/sslsync.log.
  2. Creates /usr/local/goadmio/tmp/serversync if it doesn't exist.
  3. Uses port 22 if no port was given.
  4. Prints Copying SSL to <remote-server>....
  5. Copies the contents of /etc/letsencrypt/ to root@<remote-server>:/etc/letsencrypt/ with rsync, using sshpass to supply the password.
  6. Writes 1 to /usr/local/goadmio/tmp/serversync/SSL.

How the copy works

rsync setting Effect
Archive mode Copies folders recursively and keeps permissions, owners, times, and symbolic links. Let's Encrypt keeps each live certificate as a link into its archive folder, and the links keep working.
Compression The data is compressed while it is sent.
Progress Shows the progress of each file. A partly sent file can be continued.
No delete option Files on the destination that don't exist here are kept. Files with the same name are overwritten.

The folder typically holds the certificates (live and archive), the renewal settings (renewal), and the Let's Encrypt account (accounts).

What is not copied

The marker file

The command writes 1 to /usr/local/goadmio/tmp/serversync/SSL after the copy, whether it worked or not. It sits in the same folder as the other server-sync steps and is presumably how a migration records that the SSL step has run. Delete the file if you need the step to count as not done.


See also

Command Description
serversync Copy a whole GoAdmio server to another server over SSH: accounts, files, databases, SSL certificates, and settings
copy Copy one or all GoAdmio accounts (files, mail, SQLite, databases, and settings) to another GoAdmio server over SSH
mysqlsync Copy MySQL databases from a local to a remote server
smtpsync Copy the global SMTP configuration database to a remote server
fsync Copy a directory from your local server to a remote server
permitrootlogin Allow root SSH login from a specific IP
checkssl Audit SSL certificates for all hosted domains, renew those close to expiry, and send expiry alerts