← Все руководства
SSH key-based authentication + disable password login
Switch a Linux server from password SSH login to key-based authentication only -- removes the single most common attack surface (brute-forced passwords) on any internet-facing server.
Система: Ubuntu / Debian / any systemd-based LinuxSecuritySSHОфициальный сайт ↗Официальная документация ↗
Это руководство составлено на основе официальной документации SSH key-based authentication + disable password login, ссылка на которую есть выше — всегда сверяйте точные названия пакетов/версий там перед запуском этих команд на рабочем сервере, так как версии дистрибутива и проекта со временем меняются.
1Generate a key pair on your OWN machine (not the server)
ssh-keygen -t ed25519 -C "your-name@your-computer"2Copy the public key to the server
ssh-copy-id user@your-server-ipIf ssh-copy-id isn't available, manually append the contents of ~/.ssh/id_ed25519.pub to ~/.ssh/authorized_keys on the server.
3Confirm key-based login works BEFORE disabling passwords
ssh user@your-server-ipDo not proceed until this logs you in with no password prompt -- disabling password auth before confirming this can lock you out entirely.
4Disable password authentication
sudo sed -i 's/#\?PasswordAuthentication .*/PasswordAuthentication no/' /etc/ssh/sshd_configsudo systemctl restart sshd5Keep your current session open while testing a fresh one
Open a SECOND terminal and confirm a brand-new SSH connection still works before closing your original session -- your safety net if something's misconfigured.