The gpg command in Linux is used for encryption, decryption, and digital signature operations using the GNU Privacy Guard (GPG) software. GPG is a free and open-source implementation of the OpenPGP standard, providing cryptographic security and privacy for data communication.
Here’s a table explaining some of the main parameters and options of the gpg command:
| Parameter | Description |
|---|---|
| -e | Encrypt data. |
| -d | Decrypt data. |
| –sign | Create a digital signature. |
| –verify | Verify a digital signature. |
| -r | Specify recipient(s) for encryption or verification. |
| -u | Specify the user ID to use for signing or decryption. |
| –armor | Output ASCII-armored data. |
| –output | Specify the output file for encrypted, decrypted, or signed data. |
| –recipient-file | Read recipients from a file (used with -e). |
| –encrypt-to | Deprecated; specify recipients for encryption (used with -e). |
| –batch | Enable batch mode (no interaction). |
| –yes | Assume “yes” for all prompts. |
| –version | Display the GPG version information. |
| –help | Display help information about the gpg command. |
Now, let’s see some examples of how to use the gpg command:
- Encrypt a File:
gpg -e -r recipient@example.com -o encrypted_file.gpg file.txtThis command encrypts file.txt using the recipient’s public key with the email address recipient@example.com and saves the encrypted output to encrypted_file.gpg.
- Decrypt a File:
gpg -d -o decrypted_file.txt encrypted_file.gpgThis command decrypts encrypted_file.gpg and saves the decrypted content to decrypted_file.txt.
- Create a Digital Signature:
gpg --sign -u user@example.com -o file.txt.sig file.txtThis command creates a digital signature of file.txt using the private key associated with the user ID user@example.com and saves the signature to file.txt.sig.
- Verify a Digital Signature:
gpg --verify file.txt.sig file.txtThis command verifies the digital signature in file.txt.sig against the original file.txt. The signer’s public key must be available to verify the signature.
- Export Public Key:
gpg --armor --output public_key.asc --export user@example.comThis command exports the public key associated with user@example.com and saves it to public_key.asc in ASCII-armored format.
- Import Public Key:
gpg --import public_key.ascThis command imports the public key from public_key.asc into the GPG keyring.
Please note that GPG supports many more operations and options for managing keys, trust levels, keyrings, and keyserver operations. The examples provided above demonstrate basic usage for encryption, decryption, and signing. Always ensure you have a good understanding of GPG and key management to use it securely and effectively.