Skip to main content

Limit The Number Of SSH Logins Per User/Group/System

particular user tries to SSH into the system more than the allowed SSH logins, he/she will be denied access.

Limit The Number Of SSH Logins Per User Or Group On Linux

The limits.conf file is usually located under /etc/security/ directory on RPM and DEB-based systems.

Go to your remote system and edit /etc/security/limits.conf file with sudo or root user:

$ sudo nano /etc/security/limits.conf

To limit the number of concurrent SSH sessions for a specific user, for example ostechnix, Add the following line at the end:

ostechnix	hard	maxlogins	1

set number of concurrent SSH logins for user or group in limits.conf file in linux

Here,

  • ostechnix – Name of the user in my CentOS 8 server.
  • maxlogins 1 – Maximum number of logins for this user. In my case it is 1. You can increase this value to allow maximum no. of active SSH sessions per user.
  • hard – Enforcing hard limits.

If you want to limit the number of SSH connections for a group of users, add this:

@mygroup	hard    maxlogins	1

Replace @mygroup with your group name. In this scenario, all users in the mygroup can’t login via SSH more than once.

If you want to limit SSH sessions of all users (global) in the system, add this line instead:

*	hard    maxlogins	1

Here, the asterisk means global (i.e. all users in the system). Once you defined the maximum number of SSH sessions per user/group or the whole system, save and close the file.

Now try to SSH to the system with the same user more than one time. You will see an error message like below.


Too many logins for 'ostechnix'.
Last login: Tue Feb 18 17:12:09 2020 from 192.168.225.37
Connection to 192.168.225.52 closed.

Limit The Number Of SSH Logins Per User On Linux System

As you see in the above output;

  1. First, I SSH into the remote CentOS 8 server as root user via SSH and connection was successfully established.
  2. Then, I opened a new tab and SSH into the same server as normal user “ostechnix” and the connection was successful.
  3. Finally, I tried to SSH into the same server with the same user(i.e. ostechnix) and this time the connection was denied. The user “ostechnix” can not SSH into the system more than once. Because his maximum number of allowed SSH session for this user is only one time. Hence, SSH connection is denied for this user.

In this example, we restricted the total number of active SSH sessions for a user or group or all users in the system. It is also possible to limit the SSH sessions per system-basis. For example – we can allow only one SSH login from a system, not per the user or group.

Limit total number of SSH session Per System

To limit the total number of active SSH connections per system, add the following line in /etc/security/limits.conf file:

*       hard    maxsyslogins    1

Here, maxsyslogins refers the maximum number of logins on the system, not per-user or per-group.

Try to SSH into the system and you can’t access the system more than the maximum number of allowed logins on the system.

Limit total number of SSH session Per System

See? The user “ostechnix” can’t even SSH for the first time. Because, the total number of allowed SSH login is only one for the system. This time the SSH connection made by the root user has also been taken into account. So the maximum number of SSH logins has crossed the defined limit and the user “ostechnix” was denied access. Hope you understand.

Please note that this restriction applies for the normal users only. The root user can still able to login via SSH any number of times.

Comments

Popular posts from this blog

How to use Ngx-Charts in Angular ?

Charts helps us to visualize large amount of data in an easy to understand and interactive way. This helps businesses to grow more by taking important decisions from the data. For example, e-commerce can have charts or reports for product sales, with various categories like product type, year, etc. In angular, we have various charting libraries to create charts.  Ngx-charts  is one of them. Check out the list of  best angular chart libraries .  In this article, we will see data visualization with ngx-charts and how to use ngx-charts in angular application ? We will see, How to install ngx-charts in angular ? Create a vertical bar chart Create a pie chart, advanced pie chart and pie chart grid Introduction ngx-charts  is an open-source and declarative charting framework for angular2+. It is maintained by  Swimlane . It is using Angular to render and animate the SVG elements with all of its binding and speed goodness and uses d3 for the excellent math functio...

Understand Angular’s forRoot and forChild

  forRoot   /   forChild   is a pattern for singleton services that most of us know from routing. Routing is actually the main use case for it and as it is not commonly used outside of it, I wouldn’t be surprised if most Angular developers haven’t given it a second thought. However, as the official Angular documentation puts it: “Understanding how  forRoot()  works to make sure a service is a singleton will inform your development at a deeper level.” So let’s go. Providers & Injectors Angular comes with a dependency injection (DI) mechanism. When a component depends on a service, you don’t manually create an instance of the service. You  inject  the service and the dependency injection system takes care of providing an instance. import { Component, OnInit } from '@angular/core'; import { TestService } from 'src/app/services/test.service'; @Component({ selector: 'app-test', templateUrl: './test.component.html', styleUrls: ['./test.compon...

How to solve Puppeteer TimeoutError: Navigation timeout of 30000 ms exceeded

During the automation of multiple tasks on my job and personal projects, i decided to move on  Puppeteer  instead of the old school PhantomJS. One of the most usual problems with pages that contain a lot of content, because of the ads, images etc. is the load time, an exception is thrown (specifically the TimeoutError) after a page takes more than 30000ms (30 seconds) to load totally. To solve this problem, you will have 2 options, either to increase this timeout in the configuration or remove it at all. Personally, i prefer to remove the limit as i know that the pages that i work with will end up loading someday. In this article, i'll explain you briefly 2 ways to bypass this limitation. A. Globally on the tab The option that i prefer, as i browse multiple pages in the same tab, is to remove the timeout limit on the tab that i use to browse. For example, to remove the limit you should add: await page . setDefaultNavigationTimeout ( 0 ) ;  COPY SNIPPET The setDefaultNav...