Home  >  Article  >  Computer Tutorials  >  How to use GPG to encrypt and decrypt files in Linux system?

How to use GPG to encrypt and decrypt files in Linux system?

WBOY
WBOYforward
2024-02-24 13:52:021143browse

Linux系统如何使用 GPG 加密和解密文件?

In Linux systems, you can use GPG (GNU Privacy Guard) to encrypt and decrypt files. GPG is an open source encryption software used to ensure the confidentiality of files and communications. Here are the basic steps to encrypt and decrypt files using GPG:

Encrypted file:

  1. Open a terminal and log in as the user logged into the Linux system.
  2. Generate GPG key pair:

    • Run the following command to generate a GPG key pair:

      gpg --gen-key
    • Follow the prompts to provide the necessary information such as name, email address, and password. This information will be used to generate a key pair.
  3. Encrypted file:

    • Run the following command to encrypt the file:

      gpg -e -r <收件人ID> <要加密的文件>
    • Replace
      db97c40e9267f5bc31fd9c3a3f715d9a is the GPG key ID of the recipient, which can be its name, email address, or fingerprint of the key.
    • Replace
      e508efcfd42bbcefc671990b2cf7ba23 is the path and name of the file to be encrypted.
  4. GPG will encrypt the file using the recipient's public key and generate an encrypted file in the current directory.

Decrypt file:

  1. Open a terminal and log in as the user logged into the Linux system.
  2. Decrypt file:

    • Run the following command to decrypt the file:

      gpg -d <要解密的文件>
    • Replace
      5468688ececcd02bfe895d98b9d5bcd8 is the path and name of the file to be decrypted.
  3. GPG will ask you to enter your private key password. After entering the correct password, GPG will decrypt the file and output it to the terminal.

Through the above steps, you can use GPG to encrypt and decrypt files in Linux systems. Please note that encrypted files cannot be accessed by unauthorized persons and only those with the correct private key can decrypt the files. For security reasons, keep your private keys safe and protect them with a strong password.

The above is the detailed content of How to use GPG to encrypt and decrypt files in Linux system?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete