![](/img/trans.png)
[英]GPG failed to sign the data for a git commit. But it works after signing a local file first?
[英]GPG sign Git commit on repository owned by root
我有一个由 root 用户拥有的 Git 存储库,我可以使用sudo
访问它。 通常为了将这个 repo 与 Git 一起使用,我使用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
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.