Hands-on lab – combining gpg and tar for encrypted backups

For this lab, you'll combine tar and gpg to create an encrypted backup on a simulated backup device. You can perform this lab on either one of your virtual machines:

  1. Start off by creating your GPG keys. You will do that with the following command:
        gpg --gen-key
  1. Create some dummy files in your home directory, so that you'll have something to back up:
        touch {file1.txt,file2.txt,file3.txt,file4.txt}
  1. Create a backup directory at the root level of the filesystem. (In real life, you would have the backup directory on a separate device, but for now, this works.) Change ownership of the directory to your own account, and set the permissions so that only you can access it:
        sudo mkdir /backup
sudo chown your_username: /backup
sudo chmod 700 /backup
  1. Create an encrypted backup file of your own home directory. Compression is optional, but we'll go ahead and use xz for the best compression. (Note that you'll need to use sudo for this, because the .viminfo directory in your home directory is owned by the root user.):
        cd /home

sudo tar cJvf - your_username/ | gpg -c >

/backup/your_username_backup.tar.xz.gpg
  1. Now, let's say that either your home directory got deleted, or that you accidentally deleted some important files from your own home directory. Extract and decrypt the original home directory within the /backup directory:
        cd /backup
sudo gpg -d your_username.tar.xz.gpg | tar xvJ
ls -la your_username/

Note that, by combining tar with gpg, the -C option of tar to automatically place your home directory back within the /home directory won't work. So, you'll either need to manually copy the extracted directory back to /home, or move the encrypted backup file to /home before you extract it. Also, be aware that when you extract an encrypted archive with gpg, the ownership of the files will change to that of whoever extracted the archive. So, this probably wouldn't be a good choice for backing up an entire /home directory with home directories for multiple users. Finally, since this creates one huge archive file, any type of corruption in the archive file could cause you to lose the entire backup.

  1. End of Lab.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.105.114