I need to automate desktop configuration via Puppet, virtual terminal or ssh.

Unfortunately, invocation of gsettings via ssh or virtual terminal gives:

gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize "4"

(process:29520): dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY

When I set the $DISPLAY with export DISPLAY=:0.0 it gives another error:

(process:29862): dconf-WARNING **: failed to commit changes to dconf: Could not connect: Connection refused

What can I do?

  • I was having this same issue while trying to make gsettings changes for a vagrant image via SSH during provisioning. This solution askubuntu.com/a/326773 did the trick for me w/o all the fishing for the active connection and trying to spoof the environment. YMMV...
    – JELaVallee
    Jan 27, 2015 at 2:06
  • 1
    On Ubuntu 18.04 you may need to set not only DBUS_SESSION_BUS_ADDRESS, but also XDG_RUNTIME_DIR.
    – mejem
    Oct 3, 2019 at 15:39

2 Answers 2


The key is to set the DBUS_SESSION_BUS_ADDRESS environment variable.

On this thread I found the following script, that helps to get the correct value of that variable. It requires name of the process, that is running on the desktop, on which we want to change the dbus settings. (There can be more than 1 running graphical sessions in parallel). Lets call it discover_session_bus_address.sh


# Remember to run this script using the command "source ./filename.sh"

# Search these processes for the session variable 
# (they are run as the current user and have the DBUS session variable set)
compatiblePrograms=( nautilus kdeinit kded4 pulseaudio trackerd )

# Attempt to get a program pid
for index in ${compatiblePrograms[@]}; do
    PID=$(pidof -s ${index})
    if [[ "${PID}" != "" ]]; then
if [[ "${PID}" == "" ]]; then
    echo "Could not detect active login session"
    return 1

QUERY_ENVIRON="$(tr '\0' '\n' < /proc/${PID}/environ | grep "DBUS_SESSION_BUS_ADDRESS" | cut -d "=" -f 2-)"
if [[ "${QUERY_ENVIRON}" != "" ]]; then
    echo "Connected to session:"
    echo "Could not find dbus session ID in user environment."
    return 1

return 0

With this script we can do the following, assuming that unity process is running on the desktop, on which we want to apply our settings:

. ./discover_session_bus_address.sh unity
gsettings set org.compiz.core:/org/compiz/profiles/unity/plugins/core/ hsize "4"

And things should work OK.


I have a POST-Install script that sets my gsetting. Because I run the script as sudo the EUID is 0, there fore I have to find the $RUID (Real User ID).

here is my approach:

#!/usr/bin/env bash
# Get the Real Username
RUID=$(who | awk 'FNR == 1 {print $1}')

# Translate Real Username to Real User ID
RUSER_UID=$(id -u ${RUID})

# Set gsettings for the Real User
sudo -u ${RUID} DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/${RUSER_UID}/bus" gsettings set org.gnome.desktop.interface clock-show-date false

  • Your user ID is already stored in the $USER environment variable, and your UID in the $UID variable. When running sudo, they are in the $SUDO_USER and $SUDO_UID variables. That said, why would you even run this with sudo in the first place? Using sudo -u $YOUR_USER is just like not using sudo at all. Finally, your who | awk . . . command doesn't get your ID, it prints all IDs of all users currently logged into the system. Nov 7, 2017 at 9:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.