1) In order to encrypt a file for your friend or recipients you need to obtains his/hers GnuPG public key. It can be obtained why an email, keyserver or even usb pen device. Then import the friends public using following command:
$ gpg --import friend.pub.key
2) Once key added to your GnuPG key ring, it is time to encrypt the file(s) using your private key and the recipient's public key so that only your particular friend or recipients can decrypt it:
gpg -e -r Public_key_ID file
For example to decrypt, file myfin.rec.txt:
$ gpg -e -r A560159A myfin.rec.txt
$ gpg -e -r vivek myfin.rec.txt
$ gpg –a -e -r vivek myfin.rec.txt
gpg: 54CCC70D: There is no indication that this key really belongs to the owner
2048g/54CCC70D 2005-03-18 "Vivek G Gite (My keys for all friends) "
Primary key fingerprint: 00BD 76AB A6EC 574B F3F7 4BC5 EAF2 7147 A560 159A
Subkey fingerprint: 8D5E 4B3E 17D9 F491 CA04 D4B7 1BF4 E16C 54CC C70D
It is NOT certain that the key belongs to the person named
in the user ID. If you *really* know what you are doing,
you may answer the next question with yes
Use this key anyway? yes
-e : Encrypt data.
-r : Encrypt for user id name. You can specify the user id (vivek) or Public_key_id
(A560159A). Note use gpg --list-public-key to obtain the Public_key_ids.
-a : Create ASCII armored output so that file can be send via an email
3) Use the email to send the file to your friend/ recipients so that only he/she can decrypt it.
4) When your file reached to desire user/friend/recipients s/he need to run simply gpg command on it:
$ gpg myfin.rec.txt.asc
You need a passphrase to unlock the secret key for
user: "Vivek G Gite (My keys for all friends) "
2048-bit ELG-E key, ID 54CCC70D, created 2005-03-18 (main key ID A560159A)
Enter passphrase: MYPASS
gpg: encrypted with 2048-bit ELG-E key, ID 54CCC70D, created 2005-03-18
"Vivek G Gite (My keys for all friends) "
5) If some other person steals your file and tries to decrypt it using gpg:
$ gpg myfin.rec.txt.asc
gpg: encrypted with ELG-E key, ID 54CCC70D
gpg: decryption failed: secret key not available
It should fail with above error message and that is the whole point to use the GnuPG :)
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012
- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop