sodcalculator

10 Tech How-To

Fix Too Many Logins for User in Linux

Guide 10-8194 · Updated · Step by step

If you’re seeing “too many logins” or “maximum number of logins exceeded” when trying to sign in to a Linux user account, it usually means the system has a limit on concurrent sessions or failed attempts. This guide walks you through identifying and fixing the cause, whether it’s a session limit, a PAM setting, or a stuck process.

What You’ll Need

  • Root or sudo access to the Linux machine
  • Access to a terminal (local console or SSH)
  • Basic familiarity with command-line text editors (like nano or vim)

Step-by-Step

  1. Check if the user is currently logged in. Run who or w to see active sessions. If there are many sessions from the same user, you may need to kill some.
  2. Identify the limit source. The error can come from PAM’s pam_limits module, which enforces maxlogins or maxsyslogins in /etc/security/limits.conf or files in /etc/security/limits.d/. Check those files: grep -r maxlogins /etc/security/limits.conf /etc/security/limits.d/.
  3. If a limit exists, raise or remove it. Edit the file (e.g., sudo nano /etc/security/limits.conf) and change the line like username hard maxlogins 3 to a higher number, or comment it out with #. Save and exit.
  4. Check PAM configuration. Some distributions set limits in PAM files like /etc/pam.d/common-session or /etc/pam.d/system-auth. Look for lines with pam_limits.so; if missing, add session required pam_limits.so to enable the limits module. If the error is about failed logins, check pam_faillock or pam_tally2 settings.
  5. Clear failed login counters. If the error is due to too many failed attempts, use sudo faillock --user username --reset (for pam_faillock) or sudo pam_tally2 --user username --reset (for pam_tally2).
  6. Kill idle or stuck sessions. If the user has many sessions, you can terminate them with pkill -u username (careful, this kills all processes for that user) or use loginctl terminate-user username to end all sessions.
  7. Check SSH-specific limits. If the issue is over SSH, look at MaxSessions and MaxStartups in /etc/ssh/sshd_config. Adjust them (e.g., MaxSessions 10) and restart SSH with sudo systemctl restart sshd.
  8. Verify systemd limits. For systemd-based systems, check logind.conf for UserTasksMax or KillUserProcesses. Edit /etc/systemd/logind.conf and restart with sudo systemctl restart systemd-logind.
  9. Test the fix. Log out of all sessions and try logging in again. If it works, you’re done.

Common Mistakes

  • Editing the wrong limits file: Some systems use limits.d/ subdirectory; changes in the main file may be overridden.
  • Forgetting to restart services: Changes to PAM or SSH configs often require a restart of the relevant service or a reboot.
  • Killing all user processes: pkill -u can terminate important background jobs; prefer loginctl or targeted kills.
  • Not checking for multiple limit sources: Both PAM and SSH can impose limits, so you need to check both.

Tips

  • Use ulimit -u to see the current user process limit, but note that this is different from login limits.
  • For temporary fixes, you can use loginctl terminate-session to close specific sessions.
  • Set a reasonable maxlogins value (like 10) to prevent resource exhaustion while allowing normal use.
  • Monitor login attempts with last or journalctl -u systemd-logind to see patterns.

Troubleshooting

If the issue persists after following the steps:

  • Check for duplicate PAM lines. Some systems have multiple PAM config files; a line in one may override another. Search all files in /etc/pam.d/ for pam_limits.
  • Look at system logs. Run sudo journalctl -xe or check /var/log/auth.log for messages about login limits. The exact error message will guide you.
  • Test with a different user. If another user can log in, the problem is specific to the user’s configuration or their current sessions.
  • Reboot the system. Sometimes a reboot clears stuck sessions and reloads all configurations cleanly.
  • Check for malicious activity. If the user has many sessions they didn’t create, it could be a security issue. Investigate with last and who.

Frequently Asked Questions

What does “too many logins” mean exactly?

It means the system has a configured limit on the number of concurrent sessions or failed login attempts for that user, and that limit has been reached.

How do I see the current maxlogins value?

Run ulimit -u for process limits, but for login limits, check /etc/security/limits.conf or use grep maxlogins /etc/security/limits.conf.

Can I change the limit without root?

No, modifying system limits requires root or sudo privileges.

Will changing maxlogins affect existing sessions?

No, the change only applies to new logins. Existing sessions remain until they are closed.

What if I don’t want any limit?

You can comment out the line in limits.conf or set a very high number like 9999. Be aware this could allow resource exhaustion.

Is this the same as “too many authentication failures”?

No, that error is about SSH key or password authentication attempts, not session limits. That is handled by MaxAuthTries in sshd_config.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →