Securing your files with gpg
GPG or GnuPG is an open source software that let's you encrypt your files, which should be protected.
Please visit https://gnupg.org/ for more information.
Encrypt single file
gpg -cv --no-symkey-cache desired-file
| gpg command parameter | |
|---|---|
| -c | encryption only with symmetric cipher |
| -v | verbose (get more output) |
| --no-symkey-cache | do NOT cache the password |
Then you´ll be promted to enter a password.
This will result in a desired-file.gpg file, which can be decrypted again as follows:
gpg --no-symkey-cache desired-file.gpg
| gpg command parameter | |
|---|---|
| --no-symkey-cache | do NOT cache the password |
In case you´d omit the --no-symkey-cache flag the given password will be cached in the gpg-agent
and you won´t be promted for the password when decrypting the file.
Create an encrypted archive
tar -cvzf - desired-directory | gpg -cv > encrypted-archive.tar.gz.gpg
This command basically creates a tar file containing the files in the desired-directory and due to - this tar will be piped to the gpg command.
This gpg command will then take the piped tar and encrypt it and write the result into encrypted-archive.tar.gz.gpg.
| tar command parameter | |
|---|---|
| -c | Is used to create an archive |
| -v | verbose (get more output) |
| -z | Compress the file for smaller size |
| -f | Specifies that the file name will be mentioned next |
| gpg command parameter | |
|---|---|
| -c | encryption only with symmetric cipher |
| -v | verbose (get more output) |
Decrypt and decompress a gpg protected file
gpg -dv encrypted-archive.tar.gz.gpg | tar -xvzf -
gpg -dv encrypted-archive.tar.gz.gpg will cause a prompt, which asks for the password and then extracts the archive.
| gpg command parameter | |
|---|---|
| -d | stands for decrypt |
| -v | verbose (get more output) |
| tar command parameter | |
|---|---|
| -x | Extract the archive |
| -v | verbose (get more output) |
| -z | Decompress the archive |
| -f | Where to put the file/files |