How to limit the number of SSH logins in Centos
Centos how to limit the number of SSH login, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The first method: verified.
1.ssh timeout setting
# cd / etc/profile.d/ # create two blank files autologout.csh and autologout.sh to save the TMOUT configuration
# touch autologout.csh
# touch autologout.sh
# vi autologout.sh # Editing autologout.sh
# auto out in 5 minutes
TMOUT=300 # timeout in s
Readonly TMOUT # set the TMOUT variable read-only
Export TMOUT # set environment TMOUT
# vi autologout.csh # Editing autologout.csh
Set-r autologout 2
# chmod + x autologout.* # executable permissions, in fact, just give Ubunx.
Disconnect Client, log in to the terminal again for 5 minutes without using ssh will automatically disconnect.
2. Limit the number of ssh authentication:
/ etc/ssh/sshd_config
MaxAuthTries=3 this is only more than 3 validation errors disconnecting.
The second method: (there are still problems in the experiment)
Principle: realized through the pam authentication of the system.
1. Backup / etc/pam.d/system_auth file, change:
#% PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
Auth required pam_env.so
Auth required pam_unix.so nullok try_first_pass changed the original sufficient to required
# auth requisite pam_succeed_if.so uid > = 500quiet comment out this line
Add one line to auth required pam_tally.so deny=3unlock_time=300 and log in after 5 minutes after 3 failures.
# auth required pam_deny.so comment out this line
Account required pam_unix.so
Account sufficient pam_succeed_if.so uid