Reforço de segurança do SSH e autenticação por chaves
Proteja o serviço mais exposto dos servidores Linux: configure o SSH para permitir login somente por chave, desative padrões arriscados e reduza a superfície de ataque.
Reforço de segurança do SSH e autenticação por chaves é uma aula grátis de Linux Networking & TCP/IP for Developers no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Linux Networking & TCP/IP for Developers, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Linux Networking & TCP/IP for Developers inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Why Harden SSH
SSH is the primary remote-administration channel and a constant target of automated brute-force attacks.
Hardening SSH dramatically reduces the risk of unauthorized access with a handful of configuration changes in /etc/ssh/sshd_config.
Generating a Strong Key Pair
Prefer modern Ed25519 keys over older RSA. Generate a pair with a passphrase for defense in depth.
ssh-keygen -t ed25519 -C 'admin@server'Installing the Public Key
Copy the public key to the server's ~/.ssh/authorized_keys. The helper ssh-copy-id automates this safely.
ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@serverDisabling Password Authentication
Once key login works, turn off passwords entirely so brute-force attacks cannot succeed.
In sshd_config:
PasswordAuthentication noChallengeResponseAuthentication noUsePAM yes
PasswordAuthentication noDisabling Root Login
Never allow direct root SSH login. Log in as a normal user and escalate with sudo.
PermitRootLogin noRestricting Users
Limit who may connect with AllowUsers or AllowGroups. Anyone not listed is rejected outright.
AllowUsers admin deployChanging the Default Port
Moving off port 22 will not stop a determined attacker but cuts noisy automated scans considerably.
Remember to update your firewall rules to match.
Port 2222Limiting Authentication Attempts
Tighten the connection handshake to frustrate brute-force tools.
MaxAuthTries 3LoginGraceTime 20MaxStartups 10:30:60
MaxAuthTries 3Adding Fail2ban
fail2ban watches auth logs and temporarily bans IPs after repeated failures, blocking persistent attackers automatically.
sudo apt install fail2ban
sudo systemctl enable --now fail2banTesting Before Disconnecting
Always validate config and keep an existing session open before restarting sshd, so a mistake does not lock you out.
sudo sshd -t && sudo systemctl restart sshVerifying the Hardened Config
Confirm the effective settings the daemon will use with sshd -T, which prints the resolved configuration.
sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication'Quick Check
Test your SSH hardening knowledge.
Recap
You have hardened the most exposed Linux service:
- Ed25519 key pairs with passphrases
PasswordAuthentication noandPermitRootLogin no- User restrictions and tightened auth limits
fail2banfor automatic banning- Always
sshd -tand verify before disconnecting
This complements your firewall, VPN, and IDS lessons for layered defense.
Aprenda Linux Networking & TCP/IP for Developers com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 12
- Aulas
- 48
Perguntas Frequentes
A aula “Reforço de segurança do SSH e autenticação por chaves” é grátis?
Sim — o texto completo de “Reforço de segurança do SSH e autenticação por chaves” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Linux Networking & TCP/IP for Developers, atualize para CoddyKit PRO. O curso de Linux Networking & TCP/IP for Developers inclui 4 aulas no total.
O que vou aprender em “Reforço de segurança do SSH e autenticação por chaves”?
Proteja o serviço mais exposto dos servidores Linux: configure o SSH para permitir login somente por chave, desative padrões arriscados e reduza a superfície de ataque. Você pratica Linux Networking & TCP/IP for Developers com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Linux Networking & TCP/IP for Developers?
Nenhuma experiência prévia é necessária. Linux Networking & TCP/IP for Developers no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Reforço de segurança do SSH e autenticação por chaves”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Linux Networking & TCP/IP for Developers?
Sim. Cada aula de Linux Networking & TCP/IP for Developers inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Regras Avançadas de Firewall (nftables)
- Conceitos e Configuração de VPN
- Detecção de Intrusões na Rede (IDS)
- Reforço de segurança do SSH e autenticação por chaves