How to interact with existing dbus session through sudo?

Thiago Macieira thiago at
Tue Mar 18 15:48:07 PDT 2014

Em ter 18 mar 2014, às 17:32:25, Louise Baldwin escreveu:
> I really do appreciate your reply, but please note that, through additional
> trial and error, I have determined that it is in fact possible to interact
> with an existing dbus session through sudo ...
> I was previously attempting to do this by exporting the
> DBUS_SESSION_BUS_ADDRESS value stored in the file located within
> /home/Louise/.dbus/session-bus/
> This didn't work, and I have just now figured out why ... the
> DBUS_SESSION_BUS_ADDRESS value stored in this file does not match the one
> reported by /usr/bin/env for user Louise.

You're describing using sudo to change to a given user and access THAT user's 
session bus. I was answering what happens if you use sudo and try to access 
the original user's session bus. That's the part that is not allowed by the 
bus daemon.

In any case, as you've seen, acquiring the socket address is not a trivial 
task. That's because you have to answer "which user" and "which session of 
that user" before you can connect. Only programs started inside a given 
session should have access to that session's bus. Programs outside the session 
should not have access (by design, but technically possible).

> So my new question is: why doesn't the value for DBUS_SESSION_BUS_ADDRESS in
> /home/Louise/.dbus/session-bus/ match the value reported for Louise by env?

It should. It does here:


$ dbus-launch --autolaunch=`dbus-uuidgen --get`            

$ cat ~/.dbus/session-bus/`dbus-uuidgen --get`-0
# This file allows processes on the machine with id 
64bdb0d35d814699b433e438527a615a using 
# display :0 to find the D-Bus session bus with the below address.
# If the DBUS_SESSION_BUS_ADDRESS environment variable is set, it will
# be used rather than this file.
# See "man dbus-launch" for more details.

There's something wrong with the way that your session bus was started. I've 
seen some incorrect configurations in Linux distributions that start two busses 
by accident and no one realises the mistake.

Thiago Macieira - thiago (AT) - thiago (AT)
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

More information about the dbus mailing list