TL;DR
Back up your data to a distant server using encryption *before* sending it. This way, even if the server is compromised, your backups remain unreadable without the decryption key.
Secure Offsite Backups: A Step-by-Step Guide
- Choose an Encryption Method
- GPG (GNU Privacy Guard): A strong, free option. Good for individual files or directories.
- OpenSSL: More complex but very flexible. Useful for encrypting entire disk images.
- 7-Zip/RAR with Strong Encryption: Convenient if you’re already using these tools for compression.
This creates a public and private key. Keep your private key extremely safe!
gpg --gen-key
Follow the prompts to create a strong passphrase for your key.
- GPG (Single File):
gpg -e -r "Your Name" filename.txt
This encrypts filename.txt using your public key, creating filename.txt.gpg.
tar -czvf directory.tar.gz directory && gpg -e -r "Your Name" directory.tar.gz
This creates a compressed archive of the directory and then encrypts it.
openssl enc aes-256-cbc -salt -in filename.txt -out filename.enc
You’ll be prompted for a password. Use a strong one!
- SCP (Secure Copy): A standard, secure method.
scp filename.txt.gpg user@server_ip:/path/to/backup/directory
- Log in to your distant server and check that the encrypted file exists and has a reasonable size.
- Attempt a test decryption (see step 6) to ensure the transfer was successful.
- GPG:
gpg -d filename.txt.gpg > filename.txt
You’ll be prompted for your private key passphrase.
openssl enc aes-256-cbc -d -salt -in filename.enc -out filename.txt
You’ll be prompted for the password you used during encryption.
- Use
cronor a similar scheduler to run your backup script regularly. - Consider using a dedicated backup tool like
rsyncwith appropriate options for incremental backups and encryption. - Example Cron Job: Run the backup script every night at 2 AM.
0 2 * * * /path/to/your/backup_script.sh
- Never store your private key on the backup server! Keep it offline, encrypted, and in a secure location (e.g., a hardware security module or password manager).
- Consider creating multiple backups of your encryption keys.
- Regularly test your recovery process to ensure you can restore data successfully.