Symmetric Key Encryption with GnuPG

Posted by admin on November 4, 2009 under Tech Tips | Be the First to Comment

If you ever want to quickly protect a file by encrypting it with a simple password, you can use GnuPG and symmetric key encryption for the job. Using this method, you can use industry strength encryption like AES256 and not have to worry about public and private keys. Just remember your password and use PGP compatible software to decrypt the files when needed.

For example, this is how you can encrypt a zip file called backup.zip and output the result to a new file called backup.zip.gpg.

gpg --symmetric --cipher-algo aes256 -o backup.zip.gpg backup.zip
Enter passphrase: *******
Repeat passphrase: *******

To decrypt the file, the following will work.

gpg -d -o backup.zip backup.zip.gpg
gpg: AES256 encrypted data
Enter passphrase: *******
gpg: encrypted with 1 passphrase

For fun, here’s how to create a Gzip Tar archive (tar.gz) and encrypt it on the fly.

tar czvpf - SomeFiles/ | gpg --symmetric --cipher-algo aes256 -o backup.tar.gz.gpg
Enter passphrase: *******
Repeat passphrase: *******

To decrypt and extract in a single command, the following also works.

gpg -d backup.tar.gz.gpg | tar xzvf -
gpg: AES256 encrypted data
Enter passphrase: *******
gpg: encrypted with 1 passphrase

If you’re curious to know what other ciphers are available to you, simple use the gpg --versioncommand.

gpg --version | grep Cipher
Cipher: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH

RAR and UNRAR from Linux CLI

Posted by admin on September 23, 2009 under Tech Tips | Be the First to Comment

Two great packages available to the Linux community are RAR and UNRAR. If you are already familiar with the RAR compression format, these allow you to create, modify and extract RAR archives. For those of you that appreciate the graphical compression application for Gnome called File Roller, these packages enable it to read RAR files. For more information about the RAR format, check out rarsoft.com.

To install from Ubuntu or Debian, its as simple as:

sudo apt-get install rar unrar

To list the files in a RAR archive, use the l or v option:

rar l video.rar

To decompress a RAR archive called video.rar, simply issue the command:

unrar e video.rar

The unrar package is only intended for decompression tasks. Otherwise, just use the rar command with the e option to extract the files to the current directory.

rar e video.rar

To compress a single file called video.avi, adding it to a RAR file called video.rar:

rar a video.rar video.avi

To compress a single file called video.avi, splitting it into approximately 50 Mb files:

rar a -v50000 video.rar video.avi

This by default creates archive files starting with video.part01.rar, video.part02.rar and following the sequence to completion. To use the older and better known extension sequence format of .rar, .r00, .r01, etc, use the -vn option like so:

rar a -v50000 -vn video.rar video.avi

To compress an entire directory recursively, use the -r option:

rar a -r Documents.rar Documents/

To extract the files from an archive, such that the original directory structure is also recreated, use the x command:

rar x Documents.rar

There are so many other features available to the RAR format, so be sure to check out the man pages or the packaged documentation.

man rar
less /usr/share/doc/rar/rar.txt.gz

(if your version of less supports reading of compressed files)