2

I have an Ubuntu 20.04 system that's failing to create the per-user instance of systemd when logging in via ssh.
/var/log/auth.log

Jan 26 21:36:15 hostname sshd[4181]: pam_systemd(sshd:session): Failed to create session: No such process

systemctl is showing an error:

systemctl --user
Failed to connect to bus: No such file or directory

I've tried monitoring dbus to see what's going on:

method call time=1611694572.932842 sender=:1.3 -> destination=org.freedesktop.DBus serial=223 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetConnectionUnixUser
   string ":1.54"
method return time=1611694572.932854 sender=org.freedesktop.DBus -> destination=:1.3 serial=42 reply_serial=223
   uint32 0
method call time=1611694572.932959 sender=:1.3 -> destination=org.freedesktop.DBus serial=224 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=GetConnectionUnixProcessID
   string ":1.54"
method return time=1611694572.932971 sender=org.freedesktop.DBus -> destination=:1.3 serial=43 reply_serial=224
   uint32 4373
error time=1611694572.933461 sender=:1.3 -> destination=:1.54 error_name=System.Error.EAGAIN reply_serial=2
   string "Resource temporarily unavailable"

sshd is configured to use pam:

sshd -T| grep pam
usepam yes

And /etc/pam.d/common-session has the relevant pam_systemd.so entry:

grep systemd common-session
session optional        pam_systemd.so

Any ideas on how to diagnose this further?

1 Answer 1

1

The problem seems to be that the dbus socket is not found in the expected location. Let's see where it tries to connect:

strace -fy -e connect systemctl --user >/dev/null

connect(3<socket:[186829324]>, {sa_family=AF_UNIX, sun_path="/run/user/0/systemd/private"}, 29) = 0

Get your users id (using the id command, for example). You should have a file at /run/user/$id/systemd/private that corresponds to the users' id ( $id ). It was 0 in the strace output for my root user.

Here is the systemd code that creates that socket file:

int bus_init_private(Manager *m) {
        _cleanup_close_ int fd = -1;
        union sockaddr_union sa = {
                .un.sun_family = AF_UNIX
        };
        sd_event_source *s;
        socklen_t salen;
        int r;

        assert(m);

        if (m->private_listen_fd >= 0)
                return 0;

        if (MANAGER_IS_SYSTEM(m)) {

                /* We want the private bus only when running as init */
                if (getpid_cached() != 1)
                        return 0;

                strcpy(sa.un.sun_path, "/run/systemd/private");
                salen = SOCKADDR_UN_LEN(sa.un);
        } else {
                size_t left = sizeof(sa.un.sun_path);
                char *p = sa.un.sun_path;
                const char *e;

                e = secure_getenv("XDG_RUNTIME_DIR");
                if (!e) {
                        log_error("Failed to determine XDG_RUNTIME_DIR");
                        return -EHOSTDOWN;
                }

                left = strpcpy(&p, left, e);
                left = strpcpy(&p, left, "/systemd/private");

                salen = sizeof(sa.un) - left;
        }

        (void) mkdir_parents_label(sa.un.sun_path, 0755);
        (void) unlink(sa.un.sun_path);

        fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
        if (fd < 0)
                return log_error_errno(errno, "Failed to allocate private socket: %m");

        r = bind(fd, &sa.sa, salen);
        if (r < 0)
                return log_error_errno(errno, "Failed to bind private socket: %m");

        r = listen(fd, SOMAXCONN);
        if (r < 0)
                return log_error_errno(errno, "Failed to make private socket listening: %m");

        /* Generate an inotify event in case somebody waits for this socket to appear using inotify() */
        (void) touch(sa.un.sun_path);

        r = sd_event_add_io(m->event, &s, fd, EPOLLIN, bus_on_connection, m);
        if (r < 0)
                return log_error_errno(r, "Failed to allocate event source: %m");

        (void) sd_event_source_set_description(s, "bus-connection");

        m->private_listen_fd = fd;
        m->private_listen_event_source = s;
        fd = -1;

        log_debug("Successfully created private D-Bus server.");

        return 0;
}

Look at your logs to see if you got any of the errors listed above. Try to determine why that socket doesn't exist. Perhaps enable debug logging for systemd if it isn't obvious what's happening.

3
  • Welcome and thank you for your first answer. However this should probably be a comment rather than an answer, as it does not provide a solution but is an attempt to clarify the problem.
    – Uriel
    Oct 9, 2022 at 14:52
  • This i s a comment not a solution.
    – number9
    Oct 13, 2022 at 12:35
  • The question posed from the OP is "Any ideas on how to diagnose this further?" This is an answer to that question. Oct 18, 2022 at 18:16

You must log in to answer this question.

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