Cybersecurity News Hub
No Result
View All Result
  • Home
  • Cyber Crime
  • Cyber Security
  • Data Breach
  • Mobile Security
  • Videos
  • Advertise
  • Privacy Policy
  • Contact Us
  • Home
  • Cyber Crime
  • Cyber Security
  • Data Breach
  • Mobile Security
  • Videos
  • Advertise
  • Privacy Policy
  • Contact Us
No Result
View All Result
Cybersecurity News Hub
No Result
View All Result
Home Cyber Security

How to use GPG to encrypt and decrypt files

Cyberinchief by Cyberinchief
December 1, 2025
Reading Time: 7 mins read
0
How to use GPG to encrypt and decrypt files


GnuPG, commonly known as GPG, is an open source implementation of the Pretty Good Privacy cryptography standard. It offers symmetric and asymmetric encryption for data at rest and in transit.

This article introduces how to use GPG, demonstrates its installation on common OSes and provides instructions for its use.

How does GPG protect data?

Encryption seeks to satisfy the following three goals:

  • Authenticity. Guaranteeing the source of a message.
  • Integrity. Guaranteeing a message did not change unexpectedly.
  • Nonrepudiation. Guaranteeing the source of the message.

GPG satisfies all three goals by combining symmetric and asymmetric cryptography to protect stored files and digital communications.

Symmetric and asymmetric cryptography are critical components of today’s security and privacy strategies. Symmetric cryptography uses a single private key (shared secret) to both encrypt and decrypt data, while asymmetric cryptography uses a mathematically related public and private key pair. Data encrypted with one key can only be decrypted by the other — for example, data encrypted using the public key can only be decrypted using the related private key.

GPG combines these two approaches and enables users to ensure data privacy, source and integrity. As a result, GPG is widely used and supported.

Common GPG use cases

Consider the following ways to use GPG to secure data storage and transmission:

  • Encrypted email for confidentiality.
  • Digitally signed email for authenticity.
  • Encrypted files for data confidentiality.
  • Digitally signed software packages, scripts and other applications.
  • Digitally signed Git commits.

Consider your own workflow to determine additional ways GPG can protect your information.

Install GPG

GPG is free and open source software, helping to ensure its security and stability. It is available for common platforms, including Linux, macOS and Windows.

Most Linux distributions include GPG by default. Use the gpg –version command to verify you have a current version. Use your distribution’s preferred package manager if GPG isn’t present.

Screenshot of using the gpg --version command to display the version of GPG on the device.
Use the command to display the GPG version.

For Ubuntu, Debian Linux Mint and similar distributions, type:

sudo apt install gnupg

On Red Hat Enterprise Linux, Fedora, Rocky and similar distributions, type:

sudo dnf -y install gnupg

MacOS users can install GPG using the Homebrew package manager by typing:

brew install gnupg

MacOS users can also use the GPG Suite graphical application to manage encryption.

Those who prefer the Windows platform can access GPG two ways: GnuPG binary is the official installer from the GnuPG website, and Gpg4win is the graphical/command-line application.

How to use GPG for symmetric cryptography

Symmetric encryption offers the most straightforward management process. You must, however, be able to securely deliver the key to any remote connections where decryption needs to occur. This approach works best for data encryption scenarios on a single system or within a secure environment.

The simplest way to encrypt a file uses this command:

gpg -c private-file.txt

It results in an encrypted file named private-file.txt.gpg.

GPG prompts you to enter a passphrase to protect the file.

You can specify more detail, such as a specific file name, by using the following more complex command:

gpg --output new-private-file.txt.gpg --symmetric private-file.txt

To then decrypt the new-private-file.txt.gpg file, type:

gpg --output private-file.txt --decrypt private-file.txt.gpg

You can substitute the -o and -d flags for a little less typing. GPG automatically prompts for the passphrase you set for the private key.

Screenshot of using GPG to encrypt and decrypt a file using symmetric cryptography.
Using symmetric cryptography to encrypt and decrypt a file.
Screenshot of GPG prompting for a passphrase for the private key.
GPG asks for a passphrase for the private key.

Use this process to protect data backup files, confidential information on shared computers or resources you’re transferring to and from remote storage devices.

Note that GPG generates a new version of the file during the encryption process. The original nonencrypted file remains on the drive. Consider securely deleting it using a command such as shred.

How to generate key pairs for asymmetric cryptography

Begin using GPG by generating a public-private key pair. These keys are mathematically related. With asymmetric cryptography, if you encrypt data with one key, you must decrypt it with the other key. Here are examples of the two options:

  • Confidentiality. Encrypt with the public key, decrypt with the private key.
  • Digital signatures, integrity. Encrypt with the private key, decrypt with the public key.

On a Linux system, type the following command to generate the key pair:

gpg --full-generate-key

You have various options to customize the key length, type and other settings. GPG prompts you to enter your name and email address as part of your key identity. You can also set a strong passphrase to protect your private key.

You will likely need to share your public key with other users so they can decrypt data encrypted using your private key. Use the following command to export the required public key information:

gpg --armor --export [email protected] > pubkey.asc

If you receive another user’s public key or need to provide instructions to a recipient of your public key, use this command to import it into your system:

gpg --import pubkey.asc

Verify the key exists by typing gpg –list-public-keys. The user’s public key enables you to decrypt data encrypted with the related private key.

Screenshot of using GPG to create a key pair.
Key generation example.

How to use GPG for asymmetric cryptography

To encrypt a file using another user’s public key — therefore ensuring only that user can decrypt the data based on their possession of the related private key — type the following command:

RELATED POSTS

How Russia’s Largest Private University is Linked to a $25M Essay Mill – Krebs on Security

Malicious Go Packages Impersonate Google’s UUID Library to Steal Sensitive Data

Warning: React2Shell vulnerability already being exploited by threat actors

gpg --output secret-file.txt.gpg --encrypt --recipient [email protected] secret-file.txt

This command specifies the name of the encrypted file — secret-file.txt.gpg — and the recipient’s email address — [email protected]. You are encrypting the secret-file.txt file in this example.

At the other end of the data transfer, the user enters the following command to begin the decryption process:

gpg --output secret-file.txt --decrypt secret-file.txt.gpg

That user enters the passphrase protecting their private key to complete the process.

Screenshot of using GPG for asymmetric encryption.
Using GPG for asymmetric encryption.

Integrating GPG encryption into your daily routine can greatly enhance the security of your data. You already do backups, right? Now, you can encrypt those backups for greater confidentiality. You also conduct essential business using email. Learning how to use GPG to digitally sign messages adds a substantial layer of protection to communications.

Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to Informa TechTarget, The New Stack and CompTIA Blogs.



Source link

Buy JNews
ADVERTISEMENT
Tags: decryptencryptFilesGPG
ShareTweetPin
Cyberinchief

Cyberinchief

Related Posts

How Russia’s Largest Private University is Linked to a $25M Essay Mill – Krebs on Security
Cyber Security

How Russia’s Largest Private University is Linked to a $25M Essay Mill – Krebs on Security

December 8, 2025
Malicious Go Packages Impersonate Google’s UUID Library to Steal Sensitive Data
Cyber Security

Malicious Go Packages Impersonate Google’s UUID Library to Steal Sensitive Data

December 8, 2025
Warning: React2Shell vulnerability already being exploited by threat actors
Cyber Security

Warning: React2Shell vulnerability already being exploited by threat actors

December 7, 2025
News brief: RCE flaws persist as top cybersecurity threat
Cyber Security

News brief: RCE flaws persist as top cybersecurity threat

December 7, 2025
Barts Health NHS Confirms Cl0p Ransomware Behind Data Breach – Hackread – Cybersecurity News, Data Breaches, Tech, AI, Crypto and More
Cyber Security

Barts Health NHS Confirms Cl0p Ransomware Behind Data Breach – Hackread – Cybersecurity News, Data Breaches, Tech, AI, Crypto and More

December 6, 2025
GOLD BLADE’s strategic evolution – Sophos News
Cyber Security

GOLD BLADE’s strategic evolution – Sophos News

December 6, 2025
Next Post
Salary of a Cybersecurity personnel 💰

Salary of a Cybersecurity personnel 💰

Cyber Crime Complaint | Cyber Scam ची तक्रार कुठे करायची? #cybercrime #cybercrimeawareness

Cyber Crime Complaint | Cyber Scam ची तक्रार कुठे करायची? #cybercrime #cybercrimeawareness

Recommended Stories

Cyber Security Full Course (2025) | CISSP Course FREE | Cyber Security Training | Intellipaat

Cyber Security Full Course (2025) | CISSP Course FREE | Cyber Security Training | Intellipaat

October 29, 2025
how to complain in cyber police with application format?  | cyber crime online complaint in nepal

how to complain in cyber police with application format? | cyber crime online complaint in nepal

November 23, 2025
Bank Account Freeze? Student पर Cyber Crime Complaint | How to Unfreeze Bank Account? #cyberpunk

Bank Account Freeze? Student पर Cyber Crime Complaint | How to Unfreeze Bank Account? #cyberpunk

November 21, 2025

Popular Stories

  • Allianz Life – 1,115,061 breached accounts

    Allianz Life – 1,115,061 breached accounts

    0 shares
    Share 0 Tweet 0
  • Prosper – 17,605,276 breached accounts

    0 shares
    Share 0 Tweet 0
  • साइबर अपराध | Illegal Payment Gateway & Rented Bank Accounts | MAMTA CHOPRA

    0 shares
    Share 0 Tweet 0
  • Miljödata – 870,108 breached accounts

    0 shares
    Share 0 Tweet 0
  • Snowflake Data Breach Explained: Lessons and Protection Strategies

    0 shares
    Share 0 Tweet 0

Search

No Result
View All Result

Recent Posts

  • Top 5 Mobile App Security Threats Leaders Must Prepare for in 2026
  • Microsoft On Women In Cybersecurity At Black Hat Europe 2025 In London
  • Polisi kembali ungkap sindikat Cyber Crime kejahatan Internasional – iNews Malam 09/03

Categories

  • Cyber Crime
  • Cyber Security
  • Data Breach
  • Mobile Security
  • Videos

Newsletter

© 2025 All rights reserved by cyberinchief.com

No Result
View All Result
  • Home
  • Cyber Crime
  • Cyber Security
  • Data Breach
  • Mobile Security
  • Videos
  • Advertise
  • Privacy Policy
  • Contact Us

© 2025 All rights reserved by cyberinchief.com

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest News.

Enter your email address

Thanks, I’m not interested