gpg 使用入門

1. 生成祕鑰

gpg --full-generate-key 等價於 gpg --full-gen-key

image-20211221173837788

Real name: yellowconvict爲該祕鑰的名字,也稱爲 USER-ID

在生成祕鑰前最後一步還需要爲祕鑰設置密碼

image-20211221173530694

2. 查看公私鑰

2.1 查看公鑰

gpg --list-key

image-20211221174526296

2.2 查看私鑰

gpg --list-secret-key

image-20211221174541735

3. 導出公私鑰

--armor: 將其轉換爲ASCII碼顯示


3.1 導出公鑰

gpg --armor --output 文件名 --export 用戶ID

如:

gpg --armor --output yellowconvict.pub --export yellowconvict


3.2 導出私鑰

gpg --armor --output 輸出文件 --export-secret-keys 用戶ID

gpg --armor --output yellowconvict.pri --export-secret-keys yellowconvict
導出私鑰時需要輸入一開始爲祕鑰設置的密碼

image-20211221182210506

4. 使用公鑰加密文件

gpg --recipient 用戶ID --output 輸出文件 --encrypt 原始文件

image-20211222101605059

5. 使用私鑰解密文件

gpg --output 輸出文件 --decrypt 已加密文件

image-20211222102001474

第一次使用私鑰解密需要輸入爲祕鑰設置的密碼,之後就不需要輸入了

image-20211222101801796

6. 刪除祕鑰

必須先刪除私鑰,才能刪除公鑰

6.1 刪除私鑰

gpg --delete-secret-keys yellowconvict


6.2 刪除公鑰

gpg --delete-keys yellowconvict


7. 其他

第一次生成祕鑰時,可能出現卡住的問題,類似如下提示:

Not enough random bytes available. Please do some other work to give the OS a chance to collect more
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

解決方法:

不要退出當前終端,新建一個終端,並根據系統執行以下命令,命令執行完後,卡住的界面瞬間完成

Ubuntu:

$ sudo apt install rng-tools
$ rng -r /dev/urandom

CentOS:

$ yum install rng-tools
$ rngd -r /dev/urandom

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章