linux - GPG 在 root 拥有的存储库上签署 Git 提交
问题描述
我有一个由 root 用户拥有的 Git 存储库,我可以使用sudo
. 通常为了在 Git 中使用这个 repo,我使用sudo -E git ...
. 该-E
标志是必需的,以便 sudo 中的 Git 继承我的默认 Git 配置,例如作者...等。
我决定尝试对这个存储库进行 GPG 签名,所以我启用了这些选项。
> sudo -E git config user.email 'EMAIL' && sudo -E git config user.signingkey 'SIGNINGKEY' && sudo -E git config commit.gpgsign true && sudo -E git config tag.gpgsign true
但是在尝试提交时:
> sudo -E git commit --allow-empty -m 'Test commit'
error: gpg failed to sign the data
fatal: failed to write commit object
但是,gpg 似乎无法使用我的用户配置文件中存在的 GPG 密钥对该存储库进行签名。
我发现了有关此问题的新信息:https ://github.com/NixOS/nixpkgs/issues/57779
解决方案
我做了什么:
# Login as root.
$ sudo -i
# Set up .gitconfig and .gnupg.
% mv /root/.gitconfig /root/.gitconfig.orig
% mv /root/.gnupg /root/.gnupg.orig
% ln -s /home/$USER/.gitconfig /root/.gitconfig
% ln -s /home/$USER/.gnupg /root/.gnupg
# Ensure GPG uses given tty and ensure permissions.
% export GPG_TTY=$(tty)
% chown root $(tty)
# Simple test.
% killall gpg-agent
% echo "test" | gpg --clearsign
确保:
gpg --list-keys
包括您要签名的密钥。root
具有给定的权限$(tty)
。echo "test" | gpg --clearsign
成功运行。
如果您还使用ssh keys,类似的解决方案:
# Login as root.
$ sudo -i
# Set up .ssh.
# NOTE: we must copy these files for correct perms.
% mv /root/.ssh /root/.ssh.orig
% cp -r /home/$USER/.ssh /root/.ssh
# Do some remote action.
% git push
推荐阅读
- codeigniter-4 - 错误异常 - 包括(资产/grocery_crud/languages/english.php):无法打开流:没有这样的文件或目录
- swift - Swift CurrencyText 库对 Double 的财务值进行舍入不正确
- xcode - 错误 ITMS-90771 缺少 info.plist 值
- python - 无法使用 Tensorflow 加载多通道 TIFF 文件
- scala - 在 Scala 2.13 中将 Iterator 转换为 Iterable 的正确方法是什么?
- java - JDBC SQLite 如何判断数据库是否有活动连接
- python - 如何剪切或截断任何整数列值 - pandas
- angular - 如何通过检查元素的键来过滤数组中的元素
- python-3.x - python3 os 写入,结束文件
- java - 打印包含多个矩阵的数据文件