Installation
Install GnuPG based on Operating SystemConfigure GPG:
Create or modify the following configuration files to set up GPG:**~/.gnupg/gpg.conf**: Open the file and add the following lines:
**~/.gnupg/gpg-agent.conf**: Open the file and add the following lines:
- User Profile configuration for GPG
Generate GPG Keys
- Generate a key pair: Use the following command to generate your GPG key pair:
- Export the public key: Once the key pair is generated, you can export the public key using the key ID. Run the following command, replacing XXXXXX with your key ID:
Import existing GPG
- Obtain the GPG key file: If you have the GPG key file (with a .asc or .gpg extension) from another source, make sure you have it available on your system.
-
Import the GPG key: Open your terminal and run the following command, replacing
<KEY-FILE>with the path to your GPG key file:
- Trust the imported key (optional): By default, imported keys are not trusted. If the key belongs to someone you trust, you can manually trust it. Run the following command, replacing
<KEY-ID>with the ID of the imported key (can be found in the output of the previous command):
- Verify the imported key: You can verify that the key has been successfully imported by running the command:
Configure Git to use GPG
To enable Git commit signing with your GPG key, run the following command, replacing<YOUR-SIGNING-KEY-PUB-ID> with your key ID:
4BF70A73 2021-09-08 [SC] [expires: 2037-09-04]
Restart the terminal: After making these configurations, it’s recommended to restart the terminal for the changes to take effect.
- If you use Visual Studio Code, you can turn on signing by changing a setting.
Test GPG Setup
To test your GPG setup, you can encrypt and decrypt a message. Run the following command, replacing<PUT THE KEY ID HERE> with the key ID you used: