Ubuntu 20.04システムがあり、SSH経由でログインするとユーザー固有のsystemdインスタンスを作成できません。
/var/log/auth.log
Jan 26 21:36:15 hostname sshd[4181]: pam_systemd(sshd:session): Failed to create session: No such process
systemctlにエラーが表示されます。
systemctl --user
Failed to connect to bus: No such file or directory
何が起こっているのかを確認するためにdbusを監視してみました。
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"
pamを使用するようにsshdを設定します。
sshd -T| grep pam
usepam yes
/etc/pam.d/common-session には関連する pam_systemd.so エントリがあります。
grep systemd common-session
session optional pam_systemd.so
この問題をさらに診断する方法についてのアイデアはありますか?
ベストアンサー1
問題は、dbusソケットが予想位置にないようです。どこで接続しようとしているのか見てみましょう。
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
ユーザーIDを取得します(例:idコマンドを使用)。 /run/user/$id/systemd/private には、ユーザー ID ( $id ) に対応するファイルが必要です。私のrootユーザーのstrace出力には0があります。
ソケットファイルを生成するシステムコードは次のとおりです。
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;
}
ログを確認して、上記のエラーのいずれかが発生したことを確認してください。ソケットが存在しない理由を確認してください。何が起こっているのかわからない場合は、systemdのデバッグログを有効にできます。