📒
notebook
  • Notebook
  • DevOps
    • Git
      • 常见 Git 操作
      • 使用 SSH 连接 Git 远程仓库
      • 使用 GPG Keys 签名 Git 提交
      • Git on macOS
    • Docker
      • macOS 安装配置 Docker
      • CentOS7 安装配置 Docker CE
  • Linux
    • CentOS
      • CentOS7 安装配置 vsftpd
      • CentOS7 设置虚拟内存
      • CentOS7 使用 acme.sh 自动申请免费 SSL 证书
      • CentOS7 修改 SSH 端口号
      • CentOS7 主机初始设置
      • 阿里云 CentOS 主机常见设置
      • CentOS7 安装配置 SS
    • nginx
      • nginx 配置 301 永久重定向
      • nginx 使用 SSL证书配置 HTTPS
      • CentOS7 安装配置 nginx
      • nginx 配置 gzip 压缩
      • nginx 代理静态网页
  • Server
    • Ghost
      • macOS 安装配置 Ghost
      • CentOS7 安装配置 Ghost
    • npm & Yarn
      • Yarn 常用命令
      • CentOS7 安装卸载升级 Yarn
      • npm & Yarn 常见错误处理
      • macOS 安装卸载升级 Yarn
    • Node.js
      • Awesome Node.js
      • CentOS7 安装卸载升级 Node.js
      • macOS 安装卸载升级 Node.js
  • Web
    • Ionic
      • 创建 Ionic & Angular 项目
      • 使用 Ionic & Cordova 构建 Android 应用
      • macOS 搭建 Ionic & Cordova 开发环境
    • CSS
      • CSS 排版技巧
      • Awesome CSS
      • CSS 三栏自适应布局
    • Angular
      • Awesome Angular
      • 创建 Angular 项目
    • HTML
      • HTML head 常用标签
      • HTML 常用 DTD 声明
      • 常用网页语义结构
    • Web 技术标准
    • JavaScript
      • Awesome JavaScript
      • JavaScript 的 eval() 函数详解
  • Mobile
    • H5
      • iOS Safari Web App 配置
  • Development Environment
    • Development Utilities
      • Awesome Windows
      • macOS 安装配置 Homebrew
      • Awesome macOS
      • macOS 安装配置 iTerm2
    • FEED
      • 常用 Gulp 插件
  • Network
    • 常见公共 DNS
  • Technology Stacks for Web Front-End Development
Powered by GitBook
On this page
  • 安装 GPG
  • 生成 GPG keys
  • 添加公钥
  • 配置 Git
  • 全局默认签名
  • 本地仓库签名
  • 单次提交签名
  • 提交测试
  • 参考文献

Was this helpful?

  1. DevOps
  2. Git

使用 GPG Keys 签名 Git 提交

Previous使用 SSH 连接 Git 远程仓库NextGit on macOS

Last updated 5 years ago

Was this helpful?

安装 GPG

macOS 下载安装 。

Windows 下载安装 。

生成 GPG keys

打开 GPG Keychain , 新建 GPG keys:

  • 姓名:输入姓名。

  • 电子邮件:输入连接远程仓库使用的邮箱地址。

  • Password:输入密码,密码会在之后附加签名提交时使用,建议使用密码管理软件生成并保管,在第一次输入时可以勾选记住密码。

  • Confirm Password:再次输入密码。

展开 高级选项:

  • 注释:可以不用输入。

  • 密匙类型:选择 RSA 和 RSA。

  • 长度:选择 4096。

  • will be expire on :可不勾选即永不过期,或者勾选并设置过期日期(可手动吊销)。

点击 Generate Key,生成 GPG keys。

添加公钥

选中生成的 GPG keys,右键 复制 ,即复制了公钥内容。

前往 GitHub / Gitee / Gitlab 添加公钥。

配置 Git

全局默认签名

全局设置 Git 提交时默认使用指定的 GPG keys 签名:

git config --global commit.gpgSign true
git config --global user.signingKey <gpg-key-id>

TIps:

<gpg-key-id> 为 密钥标识 ,双击查看生成的 GPG keys 条目信息可以找到。

如需关闭全局默认签名:

git config --global commit.gpgSign false

本地仓库签名

Git 本地配置会覆盖对应的全局配置,如果针对本地仓库指定不同的 GPG keys,可进入本地项目仓库指定不同的密钥标识 :

git config commit.gpgSign true
git config user.signingKey <gpg-key-id>

或者针对当前 Git 仓库关闭默认签名:

git config commit.gpgSign false

单次提交签名

如只需单次提交时附加签名:

git commit -S -m "<message>"

提交测试

进入 Git 项目仓库,提交一次:

git commit -m "<message>"

会弹窗提示输入 GPG keys 的密码,此时可以勾选保存密码:

You need a passphrase to unlock the secret key for user: "Avin Cheng < your@email.com >" 4096-bit RSA key, ID DFAE0A11, created 2019-8-11

输入完密码后开始提交,然后 push 到远程仓库。

在 GitHub / Gitee / Gitlab 项目的 Commits 页面可以看到刚才提交记录后面有 Verified 标记。

参考文献

GPG Suite
Gpg4win
Signing commits with GPG
Git Config Documentation