Backup using tar, gpg, and ssh

It is often useful to stream backups of your data over the internet to some remote location. Often times, one may want to encrypt this data. All of this can be done in one step.

tar cf - directory | gpg --encrypt --recipient some@email.address | ssh user@remotehost 'cat - > /some/direcotry/directory-backup.tar.gpg'

In the above command it takes the tar of a directory called “directory” and then pipes it to a gpg encrypt command. It encrypts using a key that was generated with “gpg –gen-key”. It takes the encrypted data and streams it over ssh to some remote host. Then performs a cat on the file and writes it to some location that you an specify. It will still be encrypted on the remote host. Remember to import the public key on the remote host so you are able to unencrypt the file.

Be the first to comment

Leave a Reply