Failed to connect to bus 🐧 Linux

Failed to connect to bus: No such file or directory (systemctl --user / timedatectl)

The command needs the D-Bus/systemd bus, which isn’t available in this session — common over su, sudo -u, cron, containers or WSL.

Seen on: Linux

Meaning

systemctl --user needs the user’s systemd instance and XDG_RUNTIME_DIR. Switching users with su/sudo doesn’t create a login session, so the user bus isn’t there. Containers and WSL without systemd have no system bus at all.

Common causes

  • su/sudo -u to another user (no login session/XDG_RUNTIME_DIR)
  • Running inside a container or WSL without systemd
  • dbus service not running
  • Linger not enabled for user services

⚡ Quick fix

  1. Log in as the user directly (ssh user@host) or use machinectl shell user@
  2. Set XDG_RUNTIME_DIR=/run/user/$(id -u)
  3. Enable lingering: loginctl enable-linger user

Detailed fix by platform

Linux

  1. bash
    sudo loginctl enable-linger deploy
    sudo machinectl shell deploy@ /bin/bash
    export XDG_RUNTIME_DIR=/run/user/$(id -u)
    systemctl --user status

How to diagnose

  1. Session — loginctl list-sessions
  2. Runtime dir — echo $XDG_RUNTIME_DIR
  3. PID 1 — systemd?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.