![gsettings 无法通过 ssh 工作](https://linux22.com/image/1080702/gsettings%20%E6%97%A0%E6%B3%95%E9%80%9A%E8%BF%87%20ssh%20%E5%B7%A5%E4%BD%9C%20.png)
我正在尝试使用以下命令更改远程计算机上的 Unity Launcher 图标:
gsettings set com.canonical.Unity.Launcher favorites ...
而且效果很好
但当我这样做
ssh 127.0.0.1
gsettings set com.canonical.Unity.Launcher favorites ...
我明白了:
(process:9616): dconf-WARNING **: failed to commit changes to dconf: Error spawning
command line `dbus-launch --autolaunch=aaa5bb6eaa7cd50f2af1f10000000004 --binary-syntax
--close-stderr': Child process exited with code 1
以上内容适用于来自 ssh 的任何 gsettings 调用。
问题出在哪里?
答案1
我认为 dbus 没有在远程 ssh 会话中运行。您需要自己启动它,但这很容易做到:
dbus-launch gsettings set com.canonical.Unity.Launcher favorites ...
还要确保用户正确,您可以为另一个用户设置设置(如果您正在这样做),如下所示:
sudo -u other dbus-launch gsettings set com.canonical.Unity.Launcher favorites ...
以上内容假设您要更改设置的用户是“其他”,请根据需要进行更改。
答案2
如果有是正在运行的用户 dbus / X 会话,设置 DISPLAY 变量就足够了,例如
$ gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/Winter_Morning_by_Shannon_Lucas.jpg'
** (process:28787): WARNING **: Command line `dbus-launch --autolaunch=ab102316d96f4621a2f3ccef0000000b --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
** (process:28787): WARNING **: Command line `dbus-launch --autolaunch=ab102316d96f4621a2f3ccef0000000b --binary-syntax --close-stderr' exited with non-zero exit status 1: Autolaunch error: X11 initialization failed.\n
但
$ DISPLAY=:1 gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/Winter_Morning_by_Shannon_Lucas.jpg'
$
$ DISPLAY=:1 gsettings get org.gnome.desktop.background picture-uri
'file:///usr/share/backgrounds/Winter_Morning_by_Shannon_Lucas.jpg'
请注意,在这种情况下,我的显示器是:1 - 大多数情况下,主桌面是:0