【问题标题】:GPG sign Git commit on repository owned by rootGPG 在 root 拥有的存储库上签署 Git 提交
【发布时间】:2019-03-12 07:02:03
【问题描述】:

我有一个由 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

【问题讨论】:

  • 听起来(对我来说)由于过度使用sudo,您给自己带来了问题。停止使用sudo 处理日常任务,您的许多问题都会消失。删除回购并重新开始。如果您确实需要以 root 身份开发,那么只需 sudo su - 并完成它(这将是一个非常不寻常的要求,我预计会有程序问题)。
  • 这是root用户管理的root级配置,Git只是用来做版本控制的。
  • 巧合的是,我刚从谷歌来到这里,带着同样的问题。 NixOS 是一个很好的例子,因为通常以 root 编辑目录(根配置目录 /etc/nixos)
  • @user196499 这就是这个问题的原因!
  • 我发现这个问题非常微妙:github.com/NixOS/nixpkgs/issues/57779 这既是关于使用正确的 gpg-agent 也是由于 pinentry 问题导致的 tty 所有权问题。

标签: linux git gnupg gpg-agent


【解决方案1】:

我做了什么:

# 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 密钥,类似的解决方案:

# 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

【讨论】:

    猜你喜欢
    • 2014-08-17
    • 2016-08-19
    • 2019-12-28
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    相关资源
    最近更新 更多