GNU Privacy Guard(GnuPG或GPG)是一個密碼學軟體,用於加密、簽章通信內容及管理非對稱密碼學的金鑰
GNU Privacy Guard is a complete and free implementation of the OpenPGP Standard as defined RFC4880(also known as GPG).
//generate pub/private key
gpg --gen-key //select RSA-RSA
//export public key
gpg --armor --export peter@163.com > mykey.asc
//decrypt file which had been encrypted with public key
gpg --decrypt-file file.gpg
//import other guys's pub key
gpg --import lawrence.asc
//list keys
gpg --list-key
gpg $gpg --list-key
/home/peter/.gnupg/pubring.gpg
----------------------------------
pub 2048R/4EE235B6 2020-03-10
uid peter (peter from 163) <peter@163.com>
sub 2048R/826F97FB 2020-03-10
pub 2048R/D5D18161 2018-09-25
uid lawrence <lawrence@amlogic.com>
sub 2048R/7769D883 2018-09-25
//encrypt file with private key and output msg.txt.gpg
gpg --encrypt-file msg.txt -r peter -r lawrence
//Expired Subkey
gpg $gpg --list-key
/home/peter/.gnupg/pubring.gpg
----------------------------------
pub 2048R/4EE235B6 2020-03-10
uid peter (peter from 163) <peter@163.com>
sub 2048R/826F97FB 2020-03-10
gpg $gpg --edit-key 826F97FB
gpg (GnuPG) 1.4.20; Copyright (C) 2015 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.
Secret key is available.
pub 2048R/4EE235B6 created: 2020-03-10 expires: never usage: SC
trust: ultimate validity: ultimate
sub 2048R/826F97FB created: 2020-03-10 expires: never usage: E
[ultimate] (1). peter (peter from 163) <peter@163.com>
gpg> key 1
pub 2048R/4EE235B6 created: 2020-03-10 expires: never usage: SC
trust: ultimate validity: ultimate
sub* 2048R/826F97FB created: 2020-03-10 expires: never usage: E
[ultimate] (1). peter (peter from 163) <peter@163.com>
gpg> expire
Changing expiration time for a subkey.
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
参考: