🔑
Security

How to Disable SSH Password Login and Switch to Keys

24.11.2026
← All articles

Within hours of launching a VPS, automated scripts from all over the world start knocking on its SSH port. They cycle through common usernames like root, admin and test along with lists of millions of popular passwords. If the server is protected only by a password, it is under constant attack no matter how strong that password is. That is why experienced administrators disable password login early and switch to SSH keys.

Why password login is the weak spot

A password can be guessed, stolen, or found in a leaked database from some other service. Many people reuse one password for email, social media and servers, so a leak elsewhere opens the door to the server. A keylogger or malicious browser extension can also capture it as it is typed. With key authentication the server never asks for a secret: the private key stays on your computer and only the public part is placed on the server.

You can see the pressure on your own machine. On Ubuntu or Debian, count failed attempts like this:

grep "Failed password" /var/log/auth.log | wc -l
journalctl -u ssh --since "24 hours ago" | grep -c "Failed password"

Example: an online shop server in Tashkent

Picture a small electronics shop in Tashkent running its site on a VPS, with a developer, a content manager and an outside contractor all logging in by password. The contractor's laptop gets infected and its saved passwords leak. The next day an unknown process is mining cryptocurrency at full CPU. Had password login been disabled and each person used their own key, the stolen password would have been useless, and revoking the contractor's access would have taken deleting one line from authorized_keys.

Step 1: generate a key on your computer

Ed25519 is the best default on modern systems, and ssh-keygen ships with Linux, macOS and PowerShell on Windows 10/11. Set a passphrase so a stolen key file is not immediately usable.

ssh-keygen -t ed25519 -C "ali@laptop"

This creates ~/.ssh/id_ed25519 (private, never share it) and ~/.ssh/id_ed25519.pub (public, goes on the server). For very old systems use ssh-keygen -t rsa -b 4096.

Step 2: install the public key on the server

# Linux / macOS
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@example.uz

# Windows PowerShell
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@example.uz "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Then reconnect with ssh deploy@example.uz. If you get in without the account password, the key works. Do not continue until this succeeds, or you may lock yourself out.

Step 3: disable passwords in sshd

Modern /etc/ssh/sshd_config files start with Include /etc/ssh/sshd_config.d/*.conf, and sshd uses the first value it finds for each option. Put your settings in a drop-in file that sorts early:

sudo nano /etc/ssh/sshd_config.d/00-hardening.conf
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
PermitEmptyPasswords no

KbdInteractiveAuthentication matters because otherwise a password prompt may still appear through another method; older OpenSSH called it ChallengeResponseAuthentication. If you work as a regular user with sudo, set PermitRootLogin no. Cloud-image Ubuntu servers often ship 50-cloud-init.conf with PasswordAuthentication yes, which is why changes sometimes seem to have no effect. Check the effective values:

sudo sshd -t
sudo sshd -T | grep -Ei "passwordauthentication|kbdinteractive|permitrootlogin"

Step 4: reload safely and verify

Keep your current session open, reload the service, and test from a new terminal. The service is ssh on Ubuntu/Debian and sshd on AlmaLinux and other RHEL-family systems.

sudo systemctl reload ssh      # Ubuntu / Debian
sudo systemctl reload sshd     # AlmaLinux / Rocky
ssh -o PubkeyAuthentication=no -o PreferredAuthentications=password deploy@example.uz

The last command should end with "Permission denied (publickey)". If something breaks, the VPS console in your control panel is the way back in, so know where it is beforehand. VPS servers at sayt.uz are managed from the customer cabinet, and support can help if you get stuck.

Managing keys in a team

Give every person their own key, and ideally their own user account; sharing one key is as bad as sharing a password. The comment at the end of each authorized_keys line tells you whose key it is, so offboarding means deleting one line. Never send private keys by email or chat, keep key files at 600 and ~/.ssh at 700, and consider Fail2ban as an extra layer that temporarily blocks noisy IPs.

Related articles

🏴‍☠️ Nulled themes and plugins: why free premium software costs more 🛡️ Securing a Joomla site: updates, extensions and server settings 🗂️ Exposed .git directory: how your code and passwords leak 🛡️ Disabling Dangerous PHP Functions with disable_functions
🌐 Language
🇺🇿 O⁠'zbek 🇺🇿 Özbek (yangi) 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓