First of all, you have to install git, which comes with linux, and download and configure it yourself on Windows.
Note that under Windows, you need to use gitbash to enter the command line. If it is Linux, you can enter the command on the default command line.
The general idea is as follows (not necessarily correct, because I haven't done it for a while):
1. Generate a public key and private key (skip this step if you have one)
a. Open Git Bash.
b. Run the following code
ssh-keygen -t ed25519 -C "[email protected]"
c. When prompted to "Enter a file in which to save the key", you can press Enter to accept the default file location , but note that if you previously created an SSH key, ssh -keygen may overwrite another key, if you don't want this, you can specify the path manually.
d. I left the security password blank. If you want to encrypt, you can set a password and remember it
2. Add SSH keys to ssh-agent
-
Make sure ssh-agent is running. (Run the following command in gitbash)
# start the ssh-agent in the background $ eval "$(ssh-agent -s)" > Agent pid 59566
-
Add the SSH private key to ssh-agent. If you created a key with a different name or want to add an existing key with a different name, replace id_ed25519 in the command with the name of your private key file.
ssh-add ~/.ssh/id_ed25519
3. Configure Git to use SSH to sign commits and tags:
git config --global gpg.format ssh
4. Set up the SSH signing key in Git, replacing /PATH/TO/KEY.PUB with the public key path you want to use. (Usually under ~/.ssh)
$ git config --global user.signingkey /PATH/TO/.SSH/KEY.PUB
Open .gitconfig under the home folder (C:\Users under Windows, direct command line cd ~ in linux)
The final configuration file is as follows
[user]
name = your name
email = your email
signingkey = your public key (ends in .pub)
[gpg]
format = ssh
If there is no problem, add it after the code
[commit]
gpgsign = true
[tag]
gpgsign = true
In this way, both commit and tag will be automatically signed.
The final file is as follows
[user]
name = your name
email = your email
signingkey = your public key (ends in .pub)
[gpg]
format = ssh
[commit]
gpgsign = true
[tag]
gpgsign = true
3. Add the SSH signing key to your GitHub account
Copy SSH public key to clipboard
The content is as follows, starting with ssh-ed25519, must be Ctrl + A to copy all
Click on your avatar in the upper right corner of GitHub
Click here
Click here
Both must be added, otherwise the git connection will go wrong
One is connection authorization and the other is signature.
For the final verification, enter in git bash
ssh -T [email protected]
reference
About commit signature verification - GitHub Enterprise Cloud Docs