将 Git 凭证助手与 gnome-keyring 一起用作 Sudo 时出错
Error when using Git credential helper with gnome-keyring as Sudo
我一直在寻找一种在连接到使用 SSL 的 Git 服务器时安全存储凭据的方法。我遇到了@james-ward 的这个建议(我所做的唯一编辑是我更新了我们的 "system" 配置而不是 Git ()[=16 的 "global" 配置=]
sudo apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --system credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
那我就可以运行
git clone https://ipaddress/git/repo.git
凭证助手将存储我的凭证,但是当我 运行 以下内容时:
sudo git clone https://ipaddress/git/repo.git testfolder
它给我以下错误
** (process:3713): CRITICAL **: Error communicating with gnome-keyring-daemon
我有时需要 运行 sudo git 克隆,因为有时我需要克隆的目录需要它。任何帮助将不胜感激。
我使用的版本:
- git 版本 1.9.1
- Ubuntu 服务器 14.0.4
提前致谢!
-理查德 O.
I sometimes need to run sudo git clone since sometimes the directory where I need to make a clone requires it. Any help would be appreciated
您尝试将存储库克隆到其中的文件夹是由 root 创建的,因此您无权在其下写入或创建文件夹,除非您是 root (sudo
),设置权限 (chmod
或 chown
),您将能够克隆到文件夹中。
chmod 755 /path
使用 sudo
运行 作为根命令。这就像要求您的系统管理员(如果有的话)运行 给您一个命令。 root
用户 not 意味着做任何与开发相关的事情,因此 git
not 意味着被使用作为根。
一旦您以另一个用户(root 或任何其他用户)的身份 运行 命令,预计该其他用户将无法与您的常用用户正常通信(特别是,它找不到您的 gnome-密钥环守护进程在这里)。
所以,答案是:"don't do that"。如果您确实需要在特定目录中克隆,请按照 CodeWizard 的回答中的建议为自己授予该目录的权限。实际上,如果你需要在没有权限的目录中克隆,问问自己是不是做错了什么:原则上,这不应该发生(我的猜测是:你已经使用了太多 sudo
在过去,这就是为什么你到处都有 um-writable 目录的原因。
除了使用 sudo 之外,请注意,在 2016 年,libgnome-keyring
特定于 GNOME,现已弃用(自 January 2014, actually 起)。
2022 选项:git-credential-manager
Microsoft 提供了一个名为 GCM (Git Credential Manager), which you can install 的跨平台凭证助手(无需构建)并配置:
git-credential-manager-core configure
您需要 Git 2.27+ 才能使用它。
2016 选项:git-credential-libsecret
Git 2.11+(2016 年第 4 季度)包含一个使用 libsecret
.
的新凭证助手
参见 commit 87d1353 (09 Oct 2016) by Mantas Mikulėnas (grawity
)。
(由 Junio C Hamano -- gitster
-- in commit bfe800c 合并,2016 年 10 月 26 日)
A new credential helper that talks via "libsecret" with implementations of XDG Secret Service API has been added to contrib/credential/
.
it uses libsecret
which can support other implementations of XDG Secret
Service API.
但到了 2022 年,就不再需要了。见上文
正如 mati865 in 所述:
It should be noted that some distros like Arch and Fedora provide helpers available as both binary and source.
- Libsecret binary on Arch:
/usr/lib/git-core/git-credential-libsecret
, and
- Libsecret binary on Fedora:
/usr/libexec/git-core/git-credential-libsecret
.
注:如@rugk adds in the comments, for Fedora and Git v2.25.2-1 or higher, you need to install an extra package with that binary, because it has been split from the main git package:
dnf install git-credential-libsecret
我一直在寻找一种在连接到使用 SSL 的 Git 服务器时安全存储凭据的方法。我遇到了@james-ward 的这个建议(我所做的唯一编辑是我更新了我们的 "system" 配置而不是 Git ()[=16 的 "global" 配置=]
sudo apt-get install libgnome-keyring-dev
cd /usr/share/doc/git/contrib/credential/gnome-keyring
sudo make
git config --system credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring
那我就可以运行
git clone https://ipaddress/git/repo.git
凭证助手将存储我的凭证,但是当我 运行 以下内容时:
sudo git clone https://ipaddress/git/repo.git testfolder
它给我以下错误
** (process:3713): CRITICAL **: Error communicating with gnome-keyring-daemon
我有时需要 运行 sudo git 克隆,因为有时我需要克隆的目录需要它。任何帮助将不胜感激。
我使用的版本: - git 版本 1.9.1 - Ubuntu 服务器 14.0.4
提前致谢! -理查德 O.
I sometimes need to run sudo git clone since sometimes the directory where I need to make a clone requires it. Any help would be appreciated
您尝试将存储库克隆到其中的文件夹是由 root 创建的,因此您无权在其下写入或创建文件夹,除非您是 root (sudo
),设置权限 (chmod
或 chown
),您将能够克隆到文件夹中。
chmod 755 /path
使用 sudo
运行 作为根命令。这就像要求您的系统管理员(如果有的话)运行 给您一个命令。 root
用户 not 意味着做任何与开发相关的事情,因此 git
not 意味着被使用作为根。
一旦您以另一个用户(root 或任何其他用户)的身份 运行 命令,预计该其他用户将无法与您的常用用户正常通信(特别是,它找不到您的 gnome-密钥环守护进程在这里)。
所以,答案是:"don't do that"。如果您确实需要在特定目录中克隆,请按照 CodeWizard 的回答中的建议为自己授予该目录的权限。实际上,如果你需要在没有权限的目录中克隆,问问自己是不是做错了什么:原则上,这不应该发生(我的猜测是:你已经使用了太多 sudo
在过去,这就是为什么你到处都有 um-writable 目录的原因。
除了使用 sudo 之外,请注意,在 2016 年,libgnome-keyring
特定于 GNOME,现已弃用(自 January 2014, actually 起)。
2022 选项:git-credential-manager
Microsoft 提供了一个名为 GCM (Git Credential Manager), which you can install 的跨平台凭证助手(无需构建)并配置:
git-credential-manager-core configure
您需要 Git 2.27+ 才能使用它。
2016 选项:git-credential-libsecret
Git 2.11+(2016 年第 4 季度)包含一个使用 libsecret
.
参见 commit 87d1353 (09 Oct 2016) by Mantas Mikulėnas (grawity
)。
(由 Junio C Hamano -- gitster
-- in commit bfe800c 合并,2016 年 10 月 26 日)
A new credential helper that talks via "libsecret" with implementations of XDG Secret Service API has been added to
contrib/credential/
.it uses
libsecret
which can support other implementations of XDG Secret Service API.
但到了 2022 年,就不再需要了。见上文
正如 mati865 in
It should be noted that some distros like Arch and Fedora provide helpers available as both binary and source.
- Libsecret binary on Arch:
/usr/lib/git-core/git-credential-libsecret
, and- Libsecret binary on Fedora:
/usr/libexec/git-core/git-credential-libsecret
.
注:如@rugk adds in the comments, for Fedora and Git v2.25.2-1 or higher, you need to install an extra package with that binary, because it has been split from the main git package:
dnf install git-credential-libsecret