limit ssh connection in linux

How to Increase SSH Connection Limit in Linux

SSH is the most common way for developers and system administrators to connect with Linux systems. But it requires a lot of processing since it involves data encryption and decryption all the time, and is used by many applications, not just user sessions. So if there are too many users & applications engaging SSH connections then it may slow down your system, or even lead to a situation where new connections are not allowed. On the other hand, you may sometimes need to restrict number of allowed SSH connections. In this article, we will learn how to increase SSH connection limit in Linux, as well as how to reduce it.


How to Increase SSH Connection Limit in Linux

You can easily set the maximum number of SSH connections allowed by configuring MaxStartups and MaxSessions in sshd_config configuration file.

Open terminal and run the following command to open SSH configuration file.

$ sudo vi /etc/ssh/sshd_config
[sudo] password for user:

Look for MaxStartups option and update its value as per your requirement. It specifies the maximum number of concurrent unauthenticated connections that are to be allowed by SSH server. Any further connections will be dropped until any of the incoming connections are authenticated.

Here is an example to restrict SSH connections to 10.

MaxStartups 10

Alternatively, you can also use a colon based format to restrict SSH connections. Here is an example to restrict 50% connections once it reaches 5 and block 100% connections once concurrent connections reaches 10.

MaxStartups 5:50:10

Add the above line if it doesn’t already exist, and remove # at its beginning if it is present, to uncomment it.

Next look for MaxSessions option and set its value as per you requirement. It specifies the maximum number of simultaneous sessions to allow.

Here is an example to allow 5 simultaneous sessions.

MaxSessions 5

Here also, add the above line if it doesn’t exist already, and remove # at its beginning if it is present, to uncomment it.

Save and exit the file. Run the following command to restart SSH server and apply changes.

$ sudo systemctl restart ssh

In this article, we have learnt how to increase and decrease SSH connection limit in Linux. You can use these steps to restrict or increase SSH connections to your SSH server. They work on almost all Linux distributions.

This is a very useful method for system administrators to control the number of SSH connections to their system and prevent it from being overwhelmed.

Also read:

How to Disable Root Login in Linux
How to Disable Su Access to Sudo in Linux
How to Install Printer in Ubuntu Through Terminal
How to Unlock User Account in MySQL
How to Lock User Account in MySQL

2 thoughts on “How to Increase SSH Connection Limit in Linux

  1. [advadmin@MaestrOS ~]$ sudo vi /etc/ssh/sshd_config
    [advadmin@MaestrOS ~]$ sudo systemctl restart ssh
    Failed to restart ssh.service: Unit ssh.service not found.

    • Looks like openssh-server is not installed on your system. Please install it with the following command and then follow the steps mentioned in our article
      $ sudo apt-get install openssh-server

Leave a Reply

Your email address will not be published. Required fields are marked *