Skip to Content

Fix too many logins for user with detailed steps in Linux

The “too many logins for user” error occurs when a user attempts to log in to a Linux system but is denied access due to reaching the maximum allowed number of concurrent (simultaneous) login sessions.

Here’s an example scenario:

Let’s say we have a user named “alice” on a Linux system, and the system administrator has set a maximum limit of 3 concurrent logins for each user in the /etc/security/limits.conf configuration file.

If Alice already has three active terminal sessions open (perhaps she’s logged in from three different locations or terminal emulators), and she attempts to log in from a third location, she will receive an error message similar to the following:

Login failed: Too many logins for user alice

In this case, Alice is denied access because she has reached the maximum allowed number of concurrent logins. The system enforces this limit to prevent excessive resource usage and to ensure that the system remains responsive to other users’ needs.

To address this issue:

Review Configuration: Examine the /etc/security/limits.conf file or its related configurations to understand the specified limits for concurrent logins.

Session Management: Use tools like who or w to identify active user sessions and assess whether any can be disconnected or logged out.

Log Out Sessions: For users who have exceeded their allowed sessions, they should log out from additional terminals or sessions to bring their active sessions within the limit.

Increase Limit: If necessary, you can adjust the maximum login limit in the limits.conf file to accommodate more concurrent sessions, keeping resource availability in mind.

In this article, we will cover all topics in details.

Understanding too many logins for user in Linux

In Linux, the concept of “too many logins for user” typically refers to a security feature designed to limit the number of concurrent (simultaneous) login sessions that a single user can have. This is a security measure to prevent unauthorized or abusive access to the system.

The specific implementation can vary depending on the Linux distribution and the authentication mechanism being used (e.g., traditional Unix authentication, PAM – Pluggable Authentication Modules, etc.). However, the general idea is the same: to restrict the number of active logins for a user.

Here’s how this generally works:

PAM Configuration: The Pluggable Authentication Module (PAM) system in Linux allows administrators to configure authentication policies. This is where the settings for limiting concurrent logins are typically managed.

/etc/security/limits.conf: This is a configuration file where system-wide resource limits can be set, including limits on concurrent logins for users.

/etc/security/limits.d/ Directory: Some distributions organize PAM limits configurations in separate files within the limits.d directory, allowing for modular configuration.

Check concurrent (simultaneous) login sessions for a single user in Linux

You can check the number of concurrent (simultaneous) login sessions for a single user in Linux using various commands and methods. We will use who command here.

The who command shows information about currently logged-in users. To see the number of concurrent sessions for a specific user, you can grep the output for that user’s username:

who | grep username | wc -l

Replace username with the actual username you want to check. The wc -l command counts the number of lines in the output, which corresponds to the number of sessions for that user.

Understanding maxlogins in limits.conf file

Here’s an example of setting 3 concurrent logins for a user:

file /etc/security/limits.conf:

username hard maxlogins 3

Here’s the breakdown of the line maxlogins in /etc/security/limits.conf:

username: Replace this with the actual username of the user for whom you want to set the maximum number of logins. For example, if you’re setting the limit for the user named “john,” you would replace username with john. The asterisk (*) is a wildcard character that matches any user. In this context, it means that the rule applies to all users on the system.

hard: This keyword indicates that the limit specified is a hard limit. A hard limit is a strict limit that cannot be exceeded. If the user attempts to exceed this limit, they will not be allowed to open additional login sessions until they reduce the number of active sessions below the specified limit.

maxlogins: This is the keyword that specifies the resource you are limiting. In this case, it refers to the maximum number of concurrent logins.

3: Replace this number with the actual maximum number of concurrent logins you want to allow for the user. For example, if you want to allow a maximum of 10 concurrent logins for the user, you would replace 10 with 3. If the total number of concurrent logins for all users reaches 10, any further login attempts will be denied until the number of active logins drops below the limit.

Please be cautious when modifying system configuration files, especially those related to user limits and security settings. Make sure you understand the impact of the changes you’re making and consider testing them in a controlled environment before applying them to a production system.

Change maxlogins value in the /etc/security/limits.conf file

Here are the steps to change the maxlogins value in the /etc/security/limits.conf file using the vi text editor:

Open Terminal: Open a terminal on your Linux system.

Edit the File with vi: You need administrative privileges to modify system configuration files. Use the sudo vi command to open the limits.conf file for editing. Replace vi with vim if your system uses vim as the command for the enhanced version of vi.

sudo vi /etc/security/limits.conf

Navigate to the Line: Inside the vi editor, you’ll see the contents of the limits.conf file. Use the arrow keys to navigate to the line that specifies the maxlogins limit. The line should look like this:

* hard maxlogins 3

Edit the Value: Place the cursor over the number 3 that represents the current maxlogins value. Press i to enter insert mode. Modify the value to your desired limit. For example, change 3 to 5 if you want to set the limit to 5 concurrent logins.

Save and Exit: After making the change, press Esc to exit insert mode. Then type :wq and press Enter to save the file and exit vi.

If you’re changing this for SSH logins, restart the SSH service to apply the changes:

sudo systemctl restart sshd

After this change, the user should be able to login without problem.

Remember that vi can be a bit unintuitive for new users, so take your time and make sure you’re comfortable with the steps before making changes to important system files.

How to disable maxlogins

Commenting out the maxlogins entry in the /etc/security/limits.conf file might be necessary or desirable in certain situations.

You can use the # symbol at the beginning of the line.

Here’s how you can do it:

  • Open a terminal on your Linux system.
  • switch to root user
  • Use a text editor (like nano, vim, or gedit) to open the /etc/security/limits.conf file.
  • Find the line that specifies the maxlogins entry. It should look like this:
    * hard maxlogins 3
  • Comment out the line by adding a # symbol at the beginning of the line:
    # * hard maxlogins 3
  • Save the changes and exit the text editor.



In conclusion, encountering the “too many logins for user” error on a Linux system signifies that a user has exceeded the permitted number of concurrent login sessions. This security measure is in place to ensure resource allocation and prevent abuse.