I was wondering how to limit the maximum number of concurrent ssh sessions on a given machine.

Neither does MaxSessions nor MaxStartups in /etc/ssh/sshd_config seem to do what I am looking for.

Currently working on a poky embedded distro with systemd and pam.d

  • You might want to add which specific distro you use. Feb 28, 2022 at 11:06

1 Answer 1


You could use /etc/security/limits.conf for setting a maximum number of sessions per user.

If you want to allow only one session for user eagleone:

eagleone hard maxlogins 1

If you want to allow only one session for group exgroup:

@exgroup hard maxlogins 1

If you want to set the limit for all users:

* hard maxlogins 1

You might need to edit /etc/pam.d/sshd and add the following line:

session required pam_limits.so

If you exceed the login limit:

Too many logins for 'eagleone'.
Last login: Tue Feb 18 17:12:09 2020 from
Connection to closed.
  • Seems not to working in my embedded distro, although what you wrote is coherent and seems the correct solution. Any way to debug this? I manage to enter with two ssh connections even setting the hard overall (*) limit to 1
    – EagleOne
    Feb 28, 2022 at 10:56
  • Did you reboot? Feb 28, 2022 at 10:58
  • Indeed. Maybe pam.d overwrites this setting?
    – EagleOne
    Feb 28, 2022 at 11:03
  • #Also note that configuration files in /etc/security/limits.d directory, #which are read in alphabetical order, override the settings in this #file in case the domain is the same or more specific. Have you checked them? Feb 28, 2022 at 11:05
  • 1
    Well, I am out of ideas. I will leave this answer here for others with different distros searching for advice. Feb 28, 2022 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .