2016-06-24 40 views
1

我使用gpg只是爲了加密和解密的目的。禁止在gnupg中發送警告消息

我使用的命令是:

for enc: 
gpg --sign test 
for dec: 
gpg --decrypt test.gpg > test 

,但我得到以下警告消息:

gpg: Signature made Fri Jun 24 17:29:00 2016 UTC using RSA key ID XXXX 
gpg: Good signature from "[email protected]>" 
gpg: WARNING: This key is not certified with a trusted signature! 
gpg: There is no indication that the signature belongs to the owner. 

關我當然基於互聯網搜索 --status-fd, --no-comment, --no-mdc-warning,--no-tty ,--no-verbose --quiet --batch, --no-greeting etc嘗試。

有沒有辦法擺脫這些警告信息?

作爲最後的選擇,我使用 How to hide command output in bash

但我認爲應該有抑制GPG警告的簡單方法。

回答

2

STDERR上正在顯示的警告,你可以將STDERR流重定向到/dev/null擺脫了警告:

gpg --decrypt test.gpg 2>/dev/null 

保存STDOUT太:

gpg --decrypt test.gpg 2>/dev/null >test 
+0

這是非常好的。我嘗試了一個類似的錯誤方式。 gpg --decrypt test.gpg 2>/dev/null> test 但在這種情況下,它覆蓋了該文件。 但你的回答很好。 它解決了這個問題。 謝謝.. –

+0

@ArunKuttiyaraVarghese很高興我能幫忙:) – heemayl

0

,但我我得到的警告信息如下:

gpg: Signature made Fri Jun 24 17:29:00 2016 UTC using RSA key ID XXXX 
gpg: Good signature from "[email protected]>" 
gpg: WARNING: This key is not certified with a trusted signature! 
gpg: There is no indication that the signature belongs to the owner. 

前兩行實際上並不是一條警告消息,而只是告訴您一個正確的簽名(您解密的文件不僅是加密的,而且還有簽名)。最後兩條消息表明簽名密鑰無法驗證。

不要簡單地丟棄所有輸出到stderr,因爲這隱藏了實際問題和錯誤!而不是簡單地抑制所有的警告和錯誤信息,更好地考慮這個單獨的信息。問題是密鑰無法驗證,即。沒有信任路徑可以建立。鑑於您驗證了密鑰(確信擁有者),最好的解決方案就是頒發證書。打開GnuPG密鑰編輯命令行:

gpg --edit-key [key-id] 

,然後證明使用sign命令的鍵。如果您想確保認證不會離開您的計算機,您也可以lsign(本地簽名)密鑰。

或者(只能用於測試環境,或者如果您確信要驗證密鑰,或絕對不必關心消息來自何處),您可以應用--trust-model always選項。