SSH server can be configured to allow an authenticating client a number of tries for a set period of time before the authentication is considered a failure. By default an SSH user is allowed 3 attempts within 120 seconds (2 minutes) to authenticate whereby the client will then be given the Permission denied error and the session closed.

The failed login will be logged and the user will then be allowed to log in again. This might slow down a malicious login attempts but will not deter brute-force attacks.

Steps to manage failed logins in SSH:

  1. Launch terminal.
  2. Open SSHd configuration file using your preferred text editor.
    $ sudo vi /etc/ssh/sshd_config
    [sudo] password for user:
  3. Search for LoginGraceTime and set the value in seconds.
    LoginGraceTime 60

    Remove # if exist at the start of the line to uncomment.

    Can also use unit such as m for minute. Set the value to 0 to disable the feature.

    LoginGraceTime 1m
  4. Search for MaxAuthTries and set the number of times authentication attempt is allowed.
    MaxAuthTries 5

    Remove # if exist at the start of the line to uncomment.

  5. Restart ssh service for changes to take effect.
    $ sudo systemctl restart sshd

Support us on Patreon if this guide has helped you. Thanks!!!

Discuss the article:

Comment anonymously. Login not required.

Share!