Cloud backup with MCrypt and S3cmd
To the Clouds
![](/var/linux_magazin/storage/images/issues/2015/171/cloud-backup/po-17087-creativ_collection.png/643644-1-eng-US/PO-17087-Creativ_Collection.png_medium.png)
Encrypted backup is easier than ever with MCrypt and the Amazon Web Service's S3cmd utility.
I will wager that one of the first things a computer teacher or resident computer guru ever said to you was: "Remember to back up your files." Over the years, I've had a couple of noteworthy backup headaches. Thankfully, the episodes were only minor mishaps, not full-fledged disasters, but these close calls made me fully understand the need for a simple and methodical backup process.
The cloud makes backups easier than ever. The configuration is no more difficult than before, and you don't have to fumble around with CDs, SSDs, backup tapes, or other physical media. Several cloud-based services specialize in cloud backup, but if you're integrating your backup system with existing scripts and standard practices, you might want a little more control over how you manage your cloud backup system. In this article, I describe how to encrypt a file or file collection using MCrypt and upload the encrypted file onto the Amazon S3 cloud. To help you better understand the encryption process and examine some additional features let's first look at two simple encryption tools.
Mmmmm
MCrypt [1] is a simple file encryption tool that is very suitable for encrypted backup scenarios. On Debian and Ubuntu, you can install MCrypt easily as follows:
# apt-get install mcrypt
This command also dutifully drops the libmcrypt4
package onto your system.
MCrypt, which is a more modern version of crypt
, takes a password and a salt. (A salt is random data used as an additional input for the encryption process.) Note that you can increase security by compressing your files before (not after) running MCrypt to increase the encrypted file's security.
Encrypting a file is as simple as typing:
# mcrypt secret_doc.odt
You'll receive the following prompts:
Enter the passphrase (maximum of 512 characters) Please use a combination of upper and lower case letters and numbers. Enter passphrase:
Note that MCrypt asks you to repeat a password twice, and you will see the file secret_doc.odt.nc
next to your original document file. The file extension ".nc
" probably refers to the letters in the word "eNCrypted."
More Options
If you have gzip installed on your system, you can automatically compress the file using gzip with the -z
switch:
# mcrypt -z zipitbuddy.sh
The output filename will be called zipitbuddy.gz.sh
.
Throwing a -u
flag into the ring means you can "unlink" the original file. Use this option with caution: After the encrypted file is created, it deletes the original file, so there's no going back if that password is incorrect. I find this mode very handy for quickly tidying up from within scripts. To use it, enter
# mcrypt -z -u mymiddlenameisdanger.cfg
and to unwrap your securely wrapped gift, enter:
# mcrypt -d -z mymiddlenameisdanger.cfg.gz.nc
Clearly, the -d
option stands for decrypt. Note the -z
switch, which is now tasked with uncompressing as opposed to compressing, so you don't have to run it through gzip manually afterward. The resulting file is no longer compressed, and you are presented with the original: mymiddlenameisdanger.cfg
.
Always My Favorite
If you open a file encrypted with MCrypt in a text viewer such as less
, you will see the following gobbledygook surrounding the default 128-bit encryption algorithm offered by MCrypt:
^@m^C@rijndael-128^@ ^@cbc^@mcrypt-sha1^@^U\<BD>^X<C4
Figure 1 shows the available encryption algorithms.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.