

快速設定 Git Commit Signature Verification
source link: https://blog.wu-boy.com/2023/10/git-commit-signature-verification/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.


大家可以看到上面這張圖的第一筆 commit 是有加上綠色框框的 Verified 標籤,這是因為我有設定 Git Commit Signature Verification,這樣的好處是可以確保每次的 commit 都是由我本人所做的,而不是其他人偽造的。這邊我們來看看如何設定 Git Commit Signature Verification。
設定 SSH Key
有兩種方式可以支援 Git Commit Signature Verification,第一種是透過 SSH Key,第二種是透過 GPG Key。這邊我們先來看看如何設定 SSH Key。
產生 SSH Key
底下是產生 SSH Key 的指令,請注意 email
參數必須要跟你的 GitHub 帳號相同,否則會無法正常運作。
ssh-keygen -t rsa -C "[email protected]"
產生完成後,你會看到類似下面的訊息
Generating public/private rsa key pair.
Enter file in which to save the key (/xxx/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /xxx/.ssh/id_rsa.
Your public key has been saved in /xxx/.ssh/id_rsa.pub.
The key fingerprint is:
相信大家現在都知道如何產生 SSH Key 了,接下來我們要把 SSH Key 加入到 GitHub 帳號中。
加入 SSH Key 到 GitHub 帳號
底下是加入 SSH Key 到 GitHub 帳號的指令
pbcopy < ~/.ssh/id_rsa.pub

設定 Git Commit Signature Verification
第一步先設定 Git Commit Signature Verification,底下是設定 Git Commit Signature Verification 的指令
git config --global commit.gpgsign true
第二步設定 Git Commit Signature Verification 的 SSH Key,底下是設定 SSH Key 的指令
git config --global gpg.format ssh
git config --global user.signingkey \
/xxx/.ssh/id_rsa.pub
其中 /Users/appleboy/.ssh/id_rsa.pub
請換成你自己的 SSH Key 路徑。完成後之後所有的 Commit 都會自動加上簽章,你可以透過 git commit -S
來手動加上簽章。
這邊注意,由於 GitHub 的設定頁面,其中 Authentication Key 跟 Signing Key 是分開設定的,故需要做兩次設定,其中 Authentication Key 是用來驗證你的身份,Signing Key 是用來驗證你的 Commit 是否為你本人所做的。如果您是用 Gitea 的話,則只需要設定一次即可。
</article
Recommend
-
48
git-commit-hook configureable git commit hook 1. Install Downlod the binary, put it into a folder of your $PATH (for example. /usr/local/bin). Ensure your user h...
-
50
In the previous posts we used traditional Machine Lea...
-
73
r/git:
-
10
Legacy LVFS S3 bucket takeover and CVE-2020-10759 fwupd signature verification bypass There were two distinct vulnerabilities: A dangling S3 bucket that belonged to LVFS (Linux V...
-
22
This blog will focus on configuring SAP BTP Cloud Integration AS2 Sender adapter and Partner Directory to dynamically select the security artifacts used for Encryption and Signature Verification by providing step-by-step instructions. ...
-
16
New issue ssh signing: Add commit & tag signing/verification via SSH keys using ssh-keygen #1041 ...
-
7
‘Malsmoke’ Exploits Microsoft’s E-Signature Verification ...
-
7
SSH commit verification now supported August 23, 2022 GitHub now supports SSH commit verification, so you can sign...
-
11
An error occurred during the signature verification. The following signatures were invalid 2234 views 1 year ago Ubuntu ...
-
10
Enabling Signature Verification for Git Commits February 2, 2024 本文有 719 个字 需要花费 4 分钟阅读
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK