apt-get install gnupg2
gpg2 --full-generate-key
# Then, just fill in as prompted
gpg2 --list-keys
# Output
pub rsa2048 2020-01-02[SC]
6 CFAA44AC11E041B0181988352FC3xxxxC39FF406
uid [absolute] haha <[email protected]>
sub rsa2048 2020-01-02[E]
Note that this [email protected]
is the user ID
6 CFAA44AC11E041B0181988352FC3xxxxC39FF406 is the user ID
gpg2 --armor --output ~/public-key.txt --export [email protected]
Now in the ~ directory, your public key will appear
gpg2 --armor --output ~/private-key.txt --export-secret-keys [email protected]
# 6 CFAA44AC11E041B0181988352FC3xxxxC39FF406 is the user identification, in--list-keys can be viewed
gpg2 --keyserver hkp://keyserver.ubuntu.com --send-keys 6CFAA44AC11E041B0181988352FC3xxxxC39FF406
gpg2 --keyserver hkp://keyserver.ubuntu.com --search-keys "[email protected]"
Here is a screenshot:
# First search [email protected], figure out the id, then
gpg2 --keyserver keyserver.ubuntu.com --recv 52FC3B13C39Fxxx6
at this time:
gpg2 --list-keys
/root/.gnupg/pubring.kbx
------------------------
pub rsa2048 2020-01-02[SC]
6 CFAA44AC11E041B01819883xxxxxxx9FF406
uid [ unknown] xxxxx <[email protected]>
sub rsa2048 2020-01-02[E]
The public key can be found.
gpg2 --recipient [email protected] --output test2.txt --encrypt test.txt
After importing the public key, you can use the public key to encrypt. test.txt is the source file, test2.txt is the encrypted file
Send the encrypted file to the party who has the private key.
gpg --recipient [email protected] --output testde.txt --decrypt ./test2.txt
At this time, you will be asked to enter the protection password when creating the key pair. After entering the password, the testde.txt file is generated.
Recommended Posts