Ubuntu – As root, I can use su to make dconf changes for another user. How to actually make them apply

command linedconf

The scenario below assumes we booted up the computer and logged in as the user bort at the login menu. This is on 14.04.2.

If I open up a terminal, as the user bort I can list a dconf setting, for example

$ dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode
0

If I were to use dconf write to change the value to 1 the menu on the left side of the screen would be hidden

$ dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1
$ dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode
1

Now the menu is hidden. Now lets assume I use dconf write to set it back to 0. The menu will appear again.

Now, if I was in one terminal as the user root and tried to use su bort -c to change the value for bort I CAN change it. I know this because in another terminal where I'm the user bort, I can use dconf read and see that the value has changed to 1. So the value has been changed BUT the menu on the left side of the screen is still visible. How can I make the change actually apply instead of just being updated in the dconf database? Ultimately I want to know this for use with Puppet's exec type but being able to do this as root from the terminal would be helpful towards that goal.

As root in a terminal:

# su bort -c "/bin/sh -c '/usr/bin/dconf write /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode 1'"

As bort in a terminal after the previous command was run:

$ dconf read /org/compiz/profiles/unity/plugins/unityshell/launcher-hide-mode
1

Yet the menu is still there. I know this sort of question has some answers on this site, such as using dbus-launch but this hasn't worked for me. Maybe it's Ubuntu version specific?

Best Answer

You don't have the DBUS_SESSION_BUS_ADDRESS environment variable set, so the changes don't stick. As your user, write down the output of

echo $DBUS_SESSION_BUS_ADDRESS

and then in the root command use

export DBUS_SESSION_BUS_ADDRESS=xxxxx && dconf write ...

which should work.

After fighting their lame attempt at hiding their socket for a bit, one working solution to automatically get the address is to borrow it via a process environment:

# requires a GUI session program that will always run:
p=`pgrep -u \`whoami\` gnome-panel`

r=`grep -z DBUS_SESSION_BUS_ADDRESS /proc/$p/environ | sed 's/^[^=]*=//'`
export DBUS_SESSION_BUS_ADDRESS=$r

Of course you'd have to pick something other than gnome-panel if you're not running that.

Works for SSH_AUTH_SOCK as well. Just leaving this here so it may help people who have so far googled unsuccessfully (like me ;) ).

Related Question