Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am attempting to run various Gnome applications via X11 Forwarding and SSH. Some applications will cause the 'dbus-launch' application to be spawned first. The problem is that dbus-launch doesn't close when the X application is exited, and therefore must be killed before the SSH session can be closed properly.

I assume the problem is that the X/Gnome applications can't connect with the main message bus daemon and therefore must launch their own copy? How can I fix this? Or what am I missing?

Here is an example. I have X11 Forwarding enabled, all seems to work fine.

[me@host ~]$ gnome-calculator &
[1] 4803

(here the gcalctool program launches and is displayed to my remove X server (Xming))

[me@host ~]$ ps
  PID TTY          TIME CMD
 4706 pts/0    00:00:00 bash
 4803 pts/0    00:00:00 gnome-calculator
 4807 pts/0    00:00:00 dbus-launch
 4870 pts/0    00:00:00 ps

(now, after closing the gcalctool app in the remote session)

[me@host ~]$ ps
  PID TTY          TIME CMD
 4706 pts/0    00:00:00 bash
 4807 pts/0    00:00:00 dbus-launch
 4898 pts/0    00:00:00 ps

Note that dbus-launch is still active. And the worst part, this prevents the SSH connection from closing properly until it is killed.

Note that the system wide message daemon is running, as can be seen here:

[me@host ~]$ ps ax
 4696 ?     Ssl   0:00 dbus-daemon --system

What am I missing here? I have never seen this behavior before. Presumably, I've only ever seen applications that can connect to the message bus daemon unhindered? I have looked in /etc/dbus-1 for answers, but don't know what to look for.

Thanks in advance for the help.


OK, I'm realizing that I'm experiencing a common problem. It seems this is a fairly common behavior, but without a good solution. I'm experiencing the SSH hang because dbus-launch is still active in the tty. But there's seemingly no good way to get the dbus-launch to happen quietly.

Looking at /etc/X11/xinit/xinitrc.d/00-start-message-bus.sh gives some clue as to what is supposed to happen with a "normal" X session. This of course doesn't work when just invoking an X application to a remote X Server.

As a temporary workaround, I've added this to my .bash_logout:

# ~/.bash_logout
pkill -u $USER -t `tty | cut -d '/' -f 3,4` dbus-launch

This will allow the SSH session to close out, but it feels kludgy. Are there any better solutions out there? What's the proper way to run remote X11 applications without dbus getting in the way?

share|improve this question

2 Answers 2

up vote 6 down vote accepted

Per dbus-launch(1):

If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use D-Bus, by default the process will attempt to invoke dbus-launch with the --autolaunch option to start up a new session bus or find the existing bus address on the X display or in a file in ~/.dbus/session-bus/

Whenever an autolaunch occurs, the application that had to start a new bus will be in its own little world; it can effectively end up starting a whole new session if it tries to use a lot of bus services. This can be suboptimal or even totally broken, depending on the app and what it tries to do.

There are two common reasons for autolaunch. One is ssh to a remote machine.

So it seems the trick is to start dbus-daemon preemptively, in such a way that programs can find it. I use:

[me@host ~]$ dbus-launch --exit-with-session gnome-terminal

which, aside from gnome-terminal, starts dbus-daemon and sets $DBUS_SESSION_BUS_ADDRESS within gnome-terminal.

Any X programs run from gnome-terminal then behave nicely, and dbus-launch cleans up after itself when gnome-terminal exits.

share|improve this answer
I marked this as the answer, I like your solution here. Thank you. Launching a gnome-terminal first, and then launching additional programs from it seems to fix my issue. Is this new behavior, though? I seemingly remember being able to launch many X forwarded windows without having this issue. Maybe newer Gnome programs are using Dbus now, so I just haven't seen this yet? –  taftster Oct 11 '12 at 3:38

I had the same problem when trying to run a remote X command, and make the session exit after the X tool had exited.

So I wanted to run

ssh -X user@remotehost "firefox -no-remote"

But had to use:

ssh -X user@remotehoste "export `dbus-launch`; dbus-launch firefox -no-remote"

After closing firefox this would also close the ssh session.


This seems to leave a load of dbus-daemon processes running on the server, so this is not optimal, adding --exit-with-session on both accounts doesn't help, because this reverts the original behaviour

share|improve this answer
You have to use single quotes in the last command (otherwise dbus-launch is run locally), but then it works. Thanks! –  l0b0 Dec 17 '13 at 16:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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