Very much inspired by this article:
Open the file /etc/ssh/sshd_config
in any text editor:
sudo nano /etc/ssh/sshd_config
Find the MaxStartups
option and set the value to the maximum simultaneous connections to allow:
MaxStartups 1
From Manpage:
MaxStartups
Specifies the maximum number of concurrent unauthenticated
connections to the SSH daemon. Additional connections will be dropped
until authentication succeeds or the LoginGraceTime expires for a
connection. The default is 10.
Alternatively, random early drop can be enabled by specifying the
three colon separated values ''start:rate:full'' (e.g. "10:30:60").
sshd(8) will refuse connection attempts with a probability of
''rate/100'' (30%) if there are currently ''start'' (10)
unauthenticated connections. The probability increases linearly and
all connection attempts are refused if the number of unauthenticated
connections reaches ''full'' (60).
Find the MaxSessions
option and set the value to the maximum simultaneous sessions to allow:
MaxSessions 1
From Manpage:
MaxSessions
Specifies the maximum number of open sessions
permitted per network connection. The default is 10.
Restart the ssh
service (or its alias sshd
):
sudo systemctl restart ssh
This will allow one single connection attempt, as well as a single active session.
However as stated, it's questionable which effect this will have on CPU consumption.