Gpg文件加密:
首先必須裝上gnupg包
1生成密鑰對:
[root@localhost ~]# gpg --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
請選擇您要使用的密鑰種類:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (僅用於簽名)
(4) RSA (僅用於簽名)
您的選擇? 1
RSA 密鑰長度應在 1024 位與 4096 位之間。
您想要用多大的密鑰尺寸?(2048)
您所要求的密鑰尺寸是 2048 位
請設定這把密鑰的有效期限。
0 = 密鑰永不過期
<n> = 密鑰在 n 天后過期
<n>w = 密鑰在 n 周後過期
<n>m = 密鑰在 n 月後過期
<n>y = 密鑰在 n 年後過期
密鑰的有效期限是?(0) 0
密鑰永遠不會過期
以上正確嗎?(y/n)y
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <[email protected]>"
真實姓名:zhangsan //這個地方必須寫,是以後的key-id
電子郵件地址:[email protected]
註釋:hahah
您選定了這個用戶標識:
“zhangsan (hahah) <[email protected]>”
更改姓名(N)、註釋(C)、電子郵件地址(E)或確定(O)/退出(Q)?O
您需要一個密碼來保護您的私鑰。
gpg: problem with the agent: Not implemented
我們需要生成大量的隨機字節。這個時候您可以多做些瑣事(像是敲打鍵盤、移動
鼠標、讀寫硬盤之類的),這會讓隨機數字發生器有更好的機會獲得足夠的熵數。
我們需要生成大量的隨機字節。這個時候您可以多做些瑣事(像是敲打鍵盤、移動
鼠標、讀寫硬盤之類的),這會讓隨機數字發生器有更好的機會獲得足夠的熵數。
gpg: 密鑰 F7940F47 被標記爲絕對信任
公鑰和私鑰已經生成並經簽名。
gpg: 正在檢查信任度數據庫
gpg: 需要 3 份勉強信任和 1 份完全信任,PGP 信任模型
gpg: 深度:0 有效性: 1 已簽名: 0 信任度:0-,0q,0n,0m,0f,1u
pub 2048R/F7940F47 2011-11-09
密鑰指紋 = 87C7 E395 E07C 38C5 62FB 6185 A005 9630 F794 0F47
uid zhangsan (hahah) <[email protected]>
sub 2048R/F1C9F981 2011-11-09
2導出公鑰:
[root@localhost ~]# gpg --export --armor zhangsan > file.key //張三就是咱們前面講到的key-id
3導入公鑰:
[root@localhost ~]# gpg --import file.key
gpg: 密鑰 F7940F47:“zhangsan (hahah) <[email protected]>”未改變
gpg: 合計被處理的數量:1
gpg: 未改變:1
4加密文件:
[root@localhost ~]# gpg --encrypt --armor -r zhangsan install.log
//看看目錄中是不是多了個install.log.asc文件,我們就可以把原來的install.log刪除了
rm -rf install.log
5解密文件
[root@localhost ~]# gpg --decrypt install.log.asc > install.log
您需要輸入密碼,才能解開這個用戶的私鑰:“zhangsan (hahah) <[email protected]>”
2048 位的 RSA 密鑰,鑰匙號 F1C9F981,建立於 2011-11-09 (主鑰匙號 F7940F47)
gpg: 由 2048 位的 RSA 密鑰加密,鑰匙號爲 F1C9F981、生成於 2011-11-09
“zhangsan (hahah) <[email protected]>”
6驗證
[root@localhost ~]# head -5 install.log
安裝 fontpackages-filesystem-1.41-1.1.el6.noarch
warning: fontpackages-filesystem-1.41-1.1.el6.noarch: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
安裝 m17n-db-1.5.5-1.1.el6.noarch
安裝 xml-common-0.6.3-32.el6.noarch
安裝 setup-2.8.14-10.el6.noarch