Ubuntu Version
Ubuntu 24.04 LTS
Desktop Environment (if applicable)
Other
Problem Description
OS: Ubuntu 24.04
Component: systemd-logind
Service: SSH/SFTP (OpenSSH)
Issue observed through PAM/systemd session management
Commands used:
- loginctl
- systemd-logind
- systemctl
- sshd
Users are intermittently unable to establish new SSH/SFTP sessions.
Observed error:
pam_systemd(sshd:session): Failed to create session:
Maximum number of sessions (8192) reached, refusing further sessions.
The server is not under CPU, memory, or storage pressure at the time of the issue.
Investigation found:
- 8,192 total sessions registered in loginctl
- 7,858 sessions in “closing” state
- 334 sessions in “active” state
Several sampled sessions remain visible in loginctl despite:
- Session leader PID no longer existing
- Corresponding session-.scope no longer existing
Example:
- Session state: closing
- Leader PID: no longer exists
- systemctl status session-.scope = Unit could not be found
This suggests stale/orphaned session records are accumulating until the logind session limit is reached, preventing new SSH/SFTP logins.
STEPS To REPRODUCE
-
Verified issue reported by users:
- Unable to establish new SSH/SFTP sessions.
-
Confirmed PAM error:
- “Maximum number of sessions (8192) reached”
-
Verified system health:
- CPU utilization normal
- Memory utilization normal
- No evidence of storage bottleneck
-
Collected session statistics:
- loginctl list-sessions
- loginctl show-session <session_id>
-
Identified a large number of sessions in “closing” state.
-
Investigated sample sessions:
- Retrieved Leader PID
- Verified PID no longer exists (ps -fp )
- Verified corresponding session scope no longer exists
(systemctl status session-.scope)
-
Reloaded systemd-logind:
- systemctl reload systemd-logind
-
Result after reload:
- Service remained healthy
- Session counts unchanged
- Stale sessions remained present
-
Reviewed systemd-logind logs:
- No obvious errors observed.
-
Please help determine the root cause of stale/orphaned session entries remaining in loginctl despite:
- Leader process no longer existing
- Session scope no longer existing
-
Is this a known issue with systemd-logind, PAM, OpenSSH, or session cleanup?
-
Is there a supported method to purge or rebuild stale logind session records without rebooting the server?
-
What is the recommended recovery action?
-
What is the expected impact of restarting systemd-logind in a production SFTP environment?
Error Messages / Logs
sshd[3157537]: pam_systemd(sshd:session): Failed to create session: Maximum number of sessions (8192) reached, refusing further sessions.
sshd[3157537]: pam_systemd(sshd:session): Failed to create session: Maximum number of sessions (8192) reached, refusing further sessions.