用GPG 给Github Commit 上一把锁

如果你没有GPG Key,你应该先生成一个:

1
gpg --full-generate-key

现在,你可以导出签名:

1
2
gpg --list-secret-keys --keyid-format LONG
gpg -a -o "pubkey.txt" --export your_key

pubkey.txt 複製到你的Github https://github.com/settings/keys
设置Git 相关:

1
2
3
4
5
git config --global user.signingkey your_key
git config --global commit.gpgsign true
git config --global gpg.program gpg
git config --global user.name "username"
git config --global user.email "username@email.com"

设置Git自动输入密码:

1
2
echo 'https://{username}:{password}@{gitserver}' >>~/.git-credentials
git config --global credential.helper store

导出备份:

1
2
gpg2 --export-secret-keys >  gpg-sec-keys.db
gpg2 --export > gpg-pub-keys.db

导入(导入私钥时会自动导入公钥):

1
2
gpg2 --import gpg-sec-keys.db
gpg2 --import gpg-pub-keys.db

注意:
有时需要写环境变量

1
2
error: gpg failed to sign the data
fatal: failed to write commit object

此时你需要

1
2
echo export GPG_TTY=$(tty) >> ~/.bashrc
source ~/.bashrc
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×