Ubuntu Technical

Ubuntu technical problems and solutions reference, a modern cookbook.

Tag Archives: tar

Customized GPG

Gpg encryption is cool. It’s so cool, that I want to keep all my important files (that means back-up files) encrypted on my external storage.

Using gpg is fairly straight forward:

1) Generate a private key.

gpg --gen-key

After answering some standard questions, the key is ready.
Note: You better not forget the password you choose, or else your encrypted files are lost forever.

2) Check you key:

gpg --list-keys

This will display a list of all available keys.

3) Encrypt a file

gpg --encrypt --recipient 'key name' foo.txt

This will generate the encrypted file: foo.txt.gpg

4) Decrypt a file

gpg --output foo2.txt --decrypt foo.txt.gpg

foo2.txt file will be created.

So, until now I presented a quick guide to encrypt/decrypt a file. However, this wasn’t enough for me. I wanted to go a little further. I wanted to be able to encrypt folders as well, and the possibility to delete the original file, and keep only the encrypted one. So, I though I write my own function.
And so, tec was born.

In short tec stands for: tar, encrypt, clean. Long description: Tarballs and encrypts the TARGET using gpg (GnuPG) encrypton. Optionally it deletes the TARGET.

I have created a repository for my function on Gitorious, feel free to check the Projects page and download it if you like.

Just copy tec.sh into /usr/bin, and you’re good to go.

cd <download directory>
sudo cp tec.sh /usr/bin

For general help, type:

tec.sh --help

Basic usage:

# with delete option, to delete the original file, and keep the encrypted one
tec.sh -dr <key> <file>
# without delete option
tec.sh -r <key> <file>

The project is in it’s early phases. Currently it only encrypts. For decryption the standard gpg commands have to be used. I plan to maintain the function, and try to add as much functionality as I can.

cheers.



Flattr this

Advertisements

Compress and Extract files with tar.gz

Or simply building a “tarball” as it is sometimes called. Even though this is a trivial task, I found myself quite often looking for the command, better yet for the options, because I tend to forget. So why not look for the command on my own blog.

Creating a tar archive

cd location_of_files_to_be_archived
tar cvzf name_of_archive.tar.gz *

Parameters explained:
– c – create
– v – verbose output
– z – –gzip, –gunzip, –ungzip filter the archive through gzip
– f – use the following file for archive

Note: The f option needs to be the last in the list of parameters. Whatever characters are following f, will be the name of the tarball.

Extract a tar archive

cd location_of_files_to_be_archived
tar xvzf name_of_archive.tar.gz *

Parameters explained:
– x – extract

Cheers



Flattr this

%d bloggers like this: