mta*_*xan 15 d-bus gnome-keyring x11
我的用例是我有一个执行软件开发的无头服务器。我通常为到它的 SSH 连接启用 X11 转发,但我不能为连接速度较慢的远程位置。
我需要安全存储和缓存我的 git 凭据,因为我经常使用树中的 18-20 个存储库,所以我使用 git-credential-gnome-keyring 作为 git credential.helper,它使用 libgnome-keyring 进行通信到 gnome-keyring-daemon。为了测试解决方案,我设置了一台带有显示器的 PC,确认密钥环在系统上默认工作,然后使用 SSH 进行尝试。它适用于 X11 转发,但没有它就无法工作。
当我在没有X11转发的情况下连接时,查询keyring时出现以下错误,工具回退到命令行提示:
** (process:18305): CRITICAL **: Error communicating with gnome-keyring-daemon
Run Code Online (Sandbox Code Playgroud)
调查表明,基本问题是 gnome-keyring-daemon 期望连接使用 dbus 与之对话。如果没有 X11 会话,dbus 不会启动,因此没有用于 gnome-keyring-daemon 和 libgnome-keyring 连接的公共 dbus 总线。
我找到了其他人针对此问题发布的两种解决方案,尽管它们都不适合我。
当连接到现有的 DBUS 端口时,基本概念是找到现有登录会话的 PID,从 procfs 转储该 PID 的环境,搜索它DBUS_SESSION_BUS_ADDRESS
,并将其导出到当前环境中。由于这是用于发布会话中所有内容所使用的 DBUS 总线的变量,因此设置它应该允许会话中的所有内容在公共 DBUS 总线上进行通信,尽管它是与不同会话相关联的总线。
来源:
https : //ubuntuforums.org/showthread.php
? t = 1059023 https://ask.fedoraproject.org/en/question/45246/error-communicating-with-gnome-keyring-daemon-in-ssh- session/
添加到我的 .bashrc 中的代码在 ssh 登录时执行:
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] ; then
local myPID=`pgrep "(.*session|fluxbox)" | head -n1`
if [ -n "$myPID" ] ; then
local myVar=`cat /proc/${myPID}/environ | grep -z "^DBUS_SESSION_BUS_ADDRESS=" | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
if [ -n "$myVar" ] ; then
export DBUS_SESSION_BUS_ADDRESS=$myVar
fi
fi
fi
Run Code Online (Sandbox Code Playgroud)
第二种方法,为会话手动启动 DBUS,涉及使用dbus-launch
创建一个新会话并设置DBUS_SESSION_BUS_ADDRESS
环境,然后使用所有必要的服务启动 gnome-keyring-daemon,这样它就会看到我们创建的 DBUS 总线地址而不是一个空的总线地址。此解决方案可能需要也可能不需要 gnome-keyring-daemon 更改为每个会话运行一个实例而不是每个系统一个实例,但尚不清楚。
来源:
从数字 8 开始:https://support.wandisco.com/index.php?/ Knowledgebase/ Article/ View/ 362/17/how-to-setup-encrypted-svn-password-storage-using-gnome- keyring-in-an-ssh-session
如何在升级时修改 dbus 服务的“Exec”行而不丢失更改
添加到我的 .bashrc 中的代码在 ssh 登录时执行:
# then DBUS wasn't started for this session and needs to be
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ] ; then
# start a new dbus session and make sure the variables are exported (automatic output)
eval `dbus-launch --sh-syntax`
# make sure gnome-keyring-daemon is using all the necessary components (it may not be by default)
# Capture the output, which is a series of variable setting commands, one on eachline, and
# export them while setting them
while read -r LINE
do
export $LINE
done <<< $(gnome-keyring-daemon --start --components=gpg,pkcs11,secrets,ssh)
fi
Run Code Online (Sandbox Code Playgroud)
两种解决方案都给出了相同的失败结果。进程并没有立即产生指示 gnome-keyring-daemon 无法与之通信的错误,而是挂起一段时间,然后产生以下输出:
Gkr-Message: secret service operation failed: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken.
** (process:31155): CRITICAL **: Error communicating with gnome-keyring-daemon
Run Code Online (Sandbox Code Playgroud)
我不清楚 gnome-keyring-daemon 如何与 DBUS 交互,但从第二组错误结果可以清楚地看出,它无法通过新创建的 DBUS 总线或不同 DBUS 总线上的跨进程访问。我发现的一些内容表明 gnome-keyring-daemon 可能需要在它之前启动 DBUS,但目前尚不清楚是使用 (libgnome-keyring) 还是守护程序的情况。
我如何让这个工作?