OpenSSH only one SSH session allowed per user at a time

Limiting the number of SSH sessions per user

If you want to set up only one SSH session allowed per user at a time in OpenSSH, this post will show you how to do it.

Edit the SSH configuration file ( /etc/ssh/sshd_config ). Use vim or nano.

sudo nano /etc/ssh/sshd_config

Add the following line to your server SSH config file. If there is another occurrence of MaxSessions , delete it or comment it out:

MaxSessions 1

Save the file and restart the SSH server. Using Nano, do CTRL + X, press Y then enter to save and close.

Restart SSH

# Ubuntu / Debian:
sudo service ssh restart

# CentOS / RHEL:
sudo systemctl restart ssh

# Fedora:
sudo systemctl restart ssh

Benefits of limiting SSH sessions

  •     Improved security: By limiting concurrent SSH sessions, your server will be secured from targeted simultaneous attacks coordinated by the same attacker.
  •     Resource Management: There is only one or limited users, so, no one is hogging resources from others due to large number of requests by multiple users.
  •     Better Monitoring: Keeping track of SSH activity is much easier, making it faster to detect any server intrusions. It is also possible to set up login notification, so that when someone logs into your server, you will get an email alert.

Leave a Comment