I access a machine through multiple login sessions. The sessions' lifetimes may or may not overlap. In my case, these login sessions are currently always over SSH, but I would prefer to handle local sessions too.

I sometimes need D-Bus in these sessions, and I want to share the same D-Bus session across these login sessions, in order to use GVFS.

What is the recommended way to do this? I don't want to break any use of D-Bus that I may not be aware of. I've considered using

export $(dbus-launch --autolaunch $(cat /var/lib/dbus/machine-id))

but (as of Ubuntu 12.04) this doesn't seem right:

  • this requires an X session, but my SSH sessions may or may not be forwarding an X display, and even the ones that are don't have the same $DISPLAY;
  • if no X display is available, dbus-launch complains that “Autolaunch error: X11 initialization failed.” and doesn't start a daemon;
  • the dbus-launch man page states that “The --autolaunch option is considered an internal implementation detail (…). There's no real reason to use it outside of the libdbus implementation anyhow.”

Does dbus-launch or another tool in the D-Bus suite support automatically detecting a running dbus-daemon and connecting to it? The necessary information is in ~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-${DISPLAY#*:} if D-Bus is started with an X connection, but doesn't seem to be stored anywhere if no X connection is available.

Should I cobble my own D-Bus session file? If I do, should I use a file in the ~/.dbus/session-bus directory? Is the path /var/lib/dbus/machine-id reliable and portable?

  • 1
    This answer might be part of a solution for you: serverfault.com/questions/405518/…
    – sdive
    Oct 5, 2012 at 9:18
  • 1
    I was fiddling with DBus a lot 2 years ago and all that is left in my memory from reading a lot, including the sources was: DBus could be cool, but is so much tailored to be run once as a system instance and exactly once again for each local user session that it's just stupid instead of cool. My guess is you have to do everything yourself. I did, but I always have X sessions so it was a little easier for me. Good luck.
    – Bananguin
    Jan 6, 2013 at 22:05
  • I've seen some nice info on dbus configuration in the BLFS book (Beyond Linux From Scratch).
    – Fiisch
    May 7, 2013 at 8:03

1 Answer 1


DBus makes sharing the settings for the dbus daemon a little tricky.

For my setup, the settings from dbus-launch --sh-syntax are saved in a file that is source by the .bash_rc. The downside of this is that, after every reboot, that process is performed manually.

However, it should be very simple to check for an existing DBus daemon. Let's say the settings file is at $HOME/.dbus_settings:


if [ -r "$HOME/.dbus_settings" ]
    . "$HOME/.dbus_settings"

    if kill -0 "$DBUS_SESSION_BUS_PID" 2>/dev/null
        need_start=0  # Found one

if [ "$need_start" -ne 0 ]
    dbus-launch --sh-syntax >"$HOME/.dbus_settings"
    . "$HOME/.dbus_settings"

Without the --autolaunch option, I don't believe an X windows connection is needed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .