簡體   English   中英

GPG 在 root 擁有的存儲庫上簽署 Git 提交

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM