Using GPG


GPG (GnuPG) stands for "The GNU Privacy Guard". GPG is a software designed to encrypt and sign data and communication.
GPG is used in zyxBackup for -optionally- encrypting the archive file. Encrypting the archive can be interesting when you upload it on a public FTP server, because then you don't care if someone can download your archive file (which can contain private data!), because nobody can open it as far as it is encrypted.

But, before being able to use this feature, you need to generate a key pair on your computer. A key pair consist of a private key and a public key.
Basically, the public key (that you can publish on a public server) is used to encrypt data, and the private key (that you have to keep private) is used to sign and decrypt data.

Let's create the key pair:
# gpg --gen-key
gpg (GnuPG) 1.4.6; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection? 1
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048
Requested keysize is 2048 bits
Please specify how long the key should be valid.
0 = key does not expire
= key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) "

Real name: MyName
Email address: none
Not a valid email address
Email address: myname@domain.com
Comment: none
You selected this USER-ID:
"MyName (none) "

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key. <-- Never forget this passphrase!

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
...+++++.++++++++++++++++++++..+++++.+++++..++++++++++++++++++++++++++++++.
+++++.+++++.+++++.+++++.+++++...++++++++++++++++++++++++++++++....+++++++++
++++++>.+++++...........................+++++


Not enough random bytes available. Please do some other work to give
the OS a chance to collect more entropy! (Need 280 more bytes)
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
.+++++..++++++++++.+++++.+++++.++++++++++.+++++..+++++.++++++++++++++++++++
++++++++++.+++++++++++++++..++++++++++.+++++.+++++++++++++++..++++++++++.++
+++++++++++++>...++++++++++>+++++>+++++....................................
...........................................................................
......................................................................>++++
+...<.+++++..................................+++++^^^

gpg: key 67A62717 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 2 signed: 1 trust: 0-, 0q, 0n, 0m, 0f, 2u
gpg: depth: 1 valid: 1 signed: 0 trust: 1-, 0q, 0n, 0m, 0f, 0u
pub 1024D/67A62717 2008-11-04
Key fingerprint = 229A 6AF4 039B F9CF DA62 5561 C87E 2A26 67A6 2717
uid MyName (none)
sub 2048g/D16DAC5C 2008-11-04


Now, you have a key pair, that you can see using commands:

# gpg --list-key (to see the public key infos)
/root/.gnupg/pubring.gpg
------------------------
pub 1024D/67A62717 2008-11-04
uid MyName (none)
sub 2048g/D16DAC5C 2008-11-04


# gpg --list-secret-key (to see the private key infos)
/root/.gnupg/secring.gpg
------------------------
sec 1024D/67A62717 2008-11-04
uid MyName (none)
ssb 2048g/D16DAC5C 2008-11-04

Note that now you have a Key ID. (Here it is 67A62717). This is this ID that you have to set in the configuration of the script when you want to encrypt the archive.
At this point, you can set zyxBackup to encrypt the final archive file. This means, that, if one day you need to restore data from an encrypted archive, you will need first to decrypt the file!

!! IMPORTANT !!
At this point you should export the private key in a file and copy it in a safe place (i.e. USB key), because, if your computer crash, and if your archive is crypted, then you don't have the private key anymore to decrypt the archive!
------------------

Exporting the private key in a file:
# gpg --export-secret-key -a > private.key.file.asc
Importing the private key from a file:
# gpg --import --allow-secret-key-import private.key.file.asc
gpg: key 2C110F05: already in secret keyring
gpg: key 67A62717: secret key imported
gpg: key 67A62717: "MyName (none) " not changed
gpg: Total number processed: 2
gpg: unchanged: 1
gpg: secret keys read: 2
gpg: secret keys imported: 1
gpg: secret keys unchanged: 1

Decrypting an archive file (this example use the uid previously created. Use yours) :
# gpg -r 67A62717 -d -o test.tar.gz test.gpg
You need a passphrase to unlock the secret key for <-- your passphrase!
user: "MyName"
1024-bit DSA key, ID 67A62717, created 2008-11-04
gpg: encrypted with 1024-bit DSA key, ID 67A62717, created 2008-11-04
"MyName"


Now you have your decryted archive :)

For more informations, see the GPG howtos and GPG official website.