Linux command
gpg 命令
安全
权限或系统影响较大,执行前请核对目标。
常用示例
Generate a new key pair
gpg --gen-key
List all keys
gpg --list-keys
Encrypt a file
gpg -e -r [recipient_email] [file]
Decrypt a file
gpg -d [file.gpg]
Sign a file
gpg --sign [file]
Verify a signature
gpg --verify [file.sig]
Export a public key
gpg --export -a "[user_id]" > [public.key]
Import a public key
gpg --import [public.key]
说明
gpg (GNU Privacy Guard) is a complete and free implementation of the OpenPGP standard as defined by RFC 4880. It allows encrypting and signing data, features a versatile key management system, and provides access modules for public key directories. GPG supports both symmetric (password-based) and asymmetric (public/private key) encryption. Common use cases include encrypting sensitive files, signing email messages, verifying software package authenticity, and establishing secure communication channels.
参数
- -e, --encrypt
- Encrypt data to one or more recipients
- -d, --decrypt
- Decrypt data (default if input looks encrypted)
- -s, --sign
- Make a signature
- --verify
- Verify a signature
- -c, --symmetric
- Encrypt with symmetric cipher using a passphrase
- -r _name_, --recipient _name_
- Encrypt for the specified recipient
- -u _name_, --local-user _name_
- Use specified key as the key to sign with
- -a, --armor
- Create ASCII armored output
- -o _file_, --output _file_
- Write output to specified file
- --gen-key
- Generate a new key pair
- --full-gen-key
- Generate a new key pair with dialog for all options
- --list-keys
- List all keys from the public keyrings
- --list-secret-keys
- List all keys from the secret keyrings
- --import
- Import keys from a file
- --export
- Export keys from the keyring
- --delete-keys _name_
- Remove keys from the public keyring
- --delete-secret-keys _name_
- Remove keys from the secret keyring
- --fingerprint
- List keys and their fingerprints
- --keyserver _url_
- Specify keyserver to use
- --send-keys _keyids_
- Send keys to a keyserver
- --recv-keys _keyids_
- Import keys from a keyserver
- --batch
- Batch mode, never ask for input
- --yes
- Assume yes on most questions
- --passphrase _string_
- Use specified passphrase
FAQ
What is the gpg command used for?
gpg (GNU Privacy Guard) is a complete and free implementation of the OpenPGP standard as defined by RFC 4880. It allows encrypting and signing data, features a versatile key management system, and provides access modules for public key directories. GPG supports both symmetric (password-based) and asymmetric (public/private key) encryption. Common use cases include encrypting sensitive files, signing email messages, verifying software package authenticity, and establishing secure communication channels.
How do I run a basic gpg example?
Run `gpg --gen-key` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -e, --encrypt do in gpg?
Encrypt data to one or more recipients