跳转到内容

GnuPG

2 posts with the tag “GnuPG”

Git 配置

本文介绍 Git 的基础配置。

对于符号链接,Windows 需要额外设置才能获得更好的兼容性。

这里重点关注 Git 在 Windows 与 Unix-like 系统之间的兼容性。

  • 配置用户名
git config --global user.name 'NAME'
  • 配置用户邮箱
git config --global user.email 'EMAIL@EXAMPLE.COM'
  • 配置 signing key
git config --global user.signingkey XXXXXXXXXXXXXXXX

XXXXXXXXXXXXXXXX:个人 GPG 私钥的 LONG 或 SHORT 格式。

  • 配置 GPG 程序
git config --global gpg.program C:\\Program Files (x86)\\GnuPG\\bin\\gpg.exe
  • 配置 Commit 和 Tag 签名
git config --global commit.gpgsign true
git config --global tag.gpgsign true

3. 在 Windows 上配置 Git,以兼容 Unix-like 系统

Section titled “3. 在 Windows 上配置 Git,以兼容 Unix-like 系统”
  • 配置 filemode 权限
git config --global core.filemode false
  • 配置 CRLF 和 LF 自动转换
git config --global core.autocrlf true
  • 配置大小写敏感
git config --global core.ignorecase false
  • 配置符号链接
git config --global core.symlinks true
  • 在 Windows 10 及以上版本中启用开发者模式。
  • 安装 Git for Windows 时启用 symlinks。
  • 组策略:
    • 进入创建符号链接权限设置:
    • Computer Configuration → Windows Settings → Security Settings → Local Policies → User Rights Assignment → Create symbolic links
    • 输入用户名,点击 “Check Names”,然后确认。
git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"
git config --global filter.lfs.process "git-lfs filter-process --skip"
[core]
symlinks = true
autocrlf = true
filemode = false
ignorecase = false
[user]
name = User Name
email = Username@example.com
signingkey = XXXXXXXXXXXXXXXX
[commit]
gpgsign = true
[tag]
gpgsign = true
[gpg]
program = C:\\Program Files (x86)\\GnuPG\\bin\\gpg.exe
[filter "lfs"]
smudge = git-lfs smudge --skip -- %f
process = git-lfs filter-process --skip
mklink [[/d] | [/h] | [/j]] <link> <target>

/d Creates a directory symbolic link. By default, this command creates a file symbolic link.

/h Creates a hard link instead of a symbolic link.

/j Creates a Directory Junction.

<link> Specifies the name of the symbolic link being created.

<target> Specifies the path (relative or absolute) that the new symbolic link refers to.

/? Displays help at the command prompt.

git tag XXXX
git tag -d <tagname>
git push origin --delete <tagname>
git push origin <tagname>
git branch -d <branchname>
git push origin --delete <branchname>

[1]. https://git-scm.com/book/en/v2/Git-Tools-Signing-Your-Work

[2]. https://github.com/git-for-windows/git/wiki/Symbolic-Links

[3]. https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink

[4]. 从一个git仓库提交代码到另一个仓库

[5]. GitLab-CI-CD-Push-to-Repository

OpenPGP 初探

gpg --expert --full-gen-key

  • --expert:专家模式。
  • --full-gen-key:生成 key。

gpg --gen-revoke -so revoke.gpg USERID

gpg --list-secret-keys 或简化命令 gpg -K

  • --keyid-format long:输出长 ID。
  • --fingerprint:输出指纹信息。

从文件导入:

gpg --import [file]

gpg -ao public-key.txt --export USERID

导出主私钥:

gpg -ao secret-key --export-secret-key 99F583599B7E31F1!

导出子密钥:

gpg -ao sign-subkey --export-secret-subkeys FDB960B857D397F6!

  • ! 表示仅导出该密钥。

删除私钥:

gpg --delete-secret-keys USERID

删除公钥:

gpg --delete-keys USERID

生成二进制签名文件:

gpg --sign input.txt

生成 ASCII 格式签名:

gpg --clearsign input.txt

签名和原文本分开:

gpg --armor --detach-sign input.txt

  • 增加 --output 参数,可以输出到文件。

验证签名文件:

gpg --verify demo.txt.asc demo.txt

gpg --recipient {keyid/uid} --output encrypt.txt --encrypt input.txt

gpg -se -o encrypt.txt -r {keyid/uid} input.txt

gpg --decrypt encrypt.txt --output decrypt.txt

gpg -d encrypt.txt

[1]. SSH-Authentication-with-GPG-Keys-on-Linux

[2]. GnuPG-Home-Configuration-on-Winodws