Introduction
The moment a new cloud server (DigitalOcean, AWS, Linode, Hetzner) is provisioned with a public IP address, automated botnets begin attacking port 22.
Bots scan millions of IPs around the clock attempting common username and password combinations (root / admin / password123).
Relying on password-based SSH authentication is an invitation for catastrophic server breach.
Cryptographic SSH key pairs completely eliminate password brute-force vectors and form the bedrock of production server security.

Generating Modern Ed25519 Key Pairs
Legacy RSA keys (2048-bit) are being superseded by the modern Ed25519 elliptic-curve algorithm.
Ed25519 keys are faster, provide stronger cryptographic security, and feature significantly shorter, easier-to-manage key strings.
Generate a new key on your local machine using: ssh-keygen -t ed25519 -C 'developer@domain.com'.
Always protect your private key with a strong local passphrase for multi-layer local defense.
Disabling Password Authentication in sshd_config
Once your public key is added to the server's ~/.ssh/authorized_keys file and tested in a separate terminal window, lock down the SSH daemon.
Edit /etc/ssh/sshd_config and set PasswordAuthentication no.
Set PermitRootLogin no and create a dedicated sudo administrative user instead of logging in as raw root.
Restart the SSH daemon (sudo systemctl restart sshd). Passwords are now completely disabled; only devices holding the cryptographic private key can connect.
Changing the Default SSH Port and Configuring UFW Firewall
While changing the default port (22) is 'security by obscurity', moving SSH to an unassigned high port (e.g. 2222 or 54321) eliminates 98% of dumb automated bot log spam.
Configure the Ubuntu Uncomplicated Firewall (UFW) to allow only your custom port, HTTP (80), and HTTPS (443).
Enable Fail2ban to automatically ban any IP address that demonstrates suspicious scanning behavior.
Your server logs remain clean, quiet, and protected.
Frequently Asked Questions
What happens if I lose my private SSH key?: If password authentication is disabled and you lose your private key, you will be locked out unless your cloud provider offers a web-based recovery console.
Can I use the same SSH key on multiple servers?: Yes, you can authorize your public key on multiple servers, but each team member should have their own personal key pair.
Where is the private key stored?: Your private key stays exclusively on your local development machine in ~/.ssh/id_ed25519. NEVER upload private keys to servers or Git.