Spin up a throwaway dbus-daemon instance and you can test D-Bus client code without going anywhere near your desktop's real session or system bus. The examples use D-Bus 1.16.2 from the installed dbus-daemon binary; the package metadata on this host reports dbus-daemon 1.14.10-4ubuntu4.1.
Allow about fifteen minutes. You need a shell and the dbus-daemon package. The first commands are ordinary user commands. Editing the system bus configuration or restarting its service requires elevated privileges and can disrupt desktop and system services, so this guide keeps all changes under /tmp.
Confirm which executable will run and read its version. This does not start a bus:
$ command -v dbus-daemon
/usr/bin/dbus-daemon
$ dbus-daemon --version
D-Bus Message Bus Daemon 1.16.2
$ dpkg-query -W -f='${Package} ${Version}\n' dbus-daemon
dbus-daemon 1.14.10-4ubuntu4.1
The executable and package can have different version strings on a managed system, for example when a locally selected binary is ahead of the package record. Use the binary's output when documenting the behaviour you actually tested.
Checkpoint: inspect the option spelling before putting it into a script:
$ dbus-daemon --help
For this workflow the useful options are --session, --nofork, --print-address, --print-pid and --config-file. The standard --session configuration is /usr/share/dbus-1/session.conf; --system selects /usr/share/dbus-1/system.conf.
A session bus is the right test target for an unprivileged, temporary launch. Run it in the foreground and ask it to print its address and PID. --nofork keeps the process attached to this shell, which makes cleanup unambiguous:
$ timeout 5s dbus-daemon --session --nofork --print-address=1 --print-pid=1
unix:path=/run/user/1000/bus,guid=0123456789abcdef0123456789abcdef
12345
Your path, GUID and PID will differ. The address is a client connection string, not a file to edit. On a normal desktop login, the standard session bus may already be owned by the session manager, so a second daemon can fail with an address or lock error. That is expected: do not solve it by stopping the desktop bus.
timeout terminates the foreground process after five seconds. A status of 124 means the timeout expired, not that the daemon rejected its configuration. If the command exits immediately with a non-zero status, read its error and check the selected configuration path.
Checkpoint: the command must print an address and a numeric PID before it is terminated. The PID should no longer exist afterwards:
$ test ! -d /proc/12345 && echo 'temporary bus stopped'
temporary bus stopped
Replace 12345 with the PID printed by your run. This launch changes no persistent configuration.
Use a separate configuration when you need a deterministic test address. This example listens on a Unix socket in /tmp, allows the local EXTERNAL authentication mechanism, and permits ordinary messages on this private bus. It is deliberately not suitable for the system bus: its broad policy is acceptable only because the socket is temporary and local.
$ conf=/tmp/dbus-guide.conf
$ socket=/tmp/dbus-guide.sock
$ rm -f "$socket"
$ cat > "$conf" <<'EOF'
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<type>session</type>
<listen>unix:path=/tmp/dbus-guide.sock</listen>
<auth>EXTERNAL</auth>
<policy context="default">
<allow send_destination="*"/>
<allow receive_sender="*"/>
<allow own="*"/>
</policy>
</busconfig>
EOF
$ chmod 600 "$conf"
$ sed -n '1,40p' "$conf"
The doctype, root element and listen address are required parts of this small configuration. The policy is intentionally simple. In a real service, grant the smallest set of own, send_destination and receive permissions needed by that service rather than copying a wildcard policy.
The rm command above removes only a stale socket at this exact path. Do not replace it with a broad temporary-directory cleanup command. The configuration contains no secret, but restricting its mode prevents unrelated users from casually reading it while you are testing.
Start the custom bus in the background so the shell can inspect it. This is still an unprivileged operation:
$ dbus-daemon --config-file="$conf" --nofork --print-address=1 --print-pid=1 \
>/tmp/dbus-guide.output 2>/tmp/dbus-guide.error &
$ bus_pid=$!
$ sleep 1
$ sed -n '1,2p' /tmp/dbus-guide.output
unix:path=/tmp/dbus-guide.sock,guid=0123456789abcdef0123456789abcdef
$ printf 'daemon pid: %s\n' "$bus_pid"
daemon pid: 23456
The GUID is generated by the daemon and will differ. Verify both the process and socket before using the address:
$ kill -0 "$bus_pid" && test -S /tmp/dbus-guide.sock && echo 'private bus is running'
private bus is running
$ test ! -s /tmp/dbus-guide.error && echo 'no daemon errors'
no daemon errors
If the socket already exists, stop the old test process, remove only /tmp/dbus-guide.sock, and retry. If the daemon exits, read /tmp/dbus-guide.error; do not add random XML elements or switch to sudo.
Stop the exact PID you recorded, then verify the socket is gone. This is the only state-changing cleanup in the guide:
$ kill "$bus_pid"
$ wait "$bus_pid" 2>/dev/null || true
$ test ! -e /tmp/dbus-guide.sock && echo 'private bus stopped'
private bus stopped
$ rm -f /tmp/dbus-guide.conf /tmp/dbus-guide.output /tmp/dbus-guide.error
If you lost the shell containing bus_pid, identify the process first with pgrep -a -x dbus-daemon and inspect carefully before sending a signal. Never kill the system or desktop bus just because it is also named dbus-daemon.
--session and --system select standard configurations. They do not mean "start a harmless isolated copy".--print-address prints a connection address. It does not make the bus reachable over the network.SIGHUP reload can be partial. Policy changes normally take effect, but some changes require a restart, which disconnects clients./etc/dbus-1/system.d for administrator overrides. Do not edit the primary files under /usr/share/dbus-1; package upgrades can replace them.