![](/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.