Instalando um Novo Servidor
Jump to navigation
Jump to search
Esboços são artigos que ainda não receberam atenção substancial. São artigos curtos ou pedaços insuficientes de informação e carecem de adição para aumentar a utilidade do artigo.
SSH
AllowUsers foo bar
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
# Configure o intervalo máximo que
# a usuária pode ficar idle antes de ser chutado
ClientAliveInterval 30
ClientAliveCountMax 2
$ sshd -t
$ service sshd restart
Fail2ban
Instalando e configurando
Em distribuições Debian é muito simples baixar e instalar o Fail2ban:
$ apt install fail2ban
$ service fail2ban status
$ fail2ban-client status sshd
[DEFAULT]
# "bantime" is the number of seconds that a host is banned.
bantime = 1h
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime = 10m
# "maxretry" is the number of failures before a host get banned.
maxretry = 5
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = %(sshd_backend)s
Monitorando
Para monitorar o funcionamento do fail2ban é possível examinar os logs e garantir que os usuários estão sendo banidos corretamente. Com o fail2ban-client podemos ter informações sobre o total de tentativas falhadas e o acumulado de usuários banidos ao longo do tempo.
$ cat /var/log/fail2ban.log | grep NOTICE
2020-07-29 00:51:08,414 fail2ban.actions [3140]: NOTICE [sshd] Ban 122.192.221.166
2020-07-29 01:51:08,325 fail2ban.actions [3140]: NOTICE [sshd] Unban 122.192.221.166
2020-07-29 02:32:52,411 fail2ban.actions [3140]: NOTICE [sshd] Ban 167.172.200.176
2020-07-29 03:32:52,228 fail2ban.actions [3140]: NOTICE [sshd] Unban 167.172.200.176
...
# fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 169
| `- File list: /var/log/auth.log
`- Actions
|- Currently banned: 0
|- Total banned: 3
`- Banned IP list: