>SSH Key Authentication: The Magic Trick That Slashed Our Server Load from 100% to Normal!

Rey Posted on 2025-10-12 100 Views


Tired of random server load spikes? Switching SSH from password to key authentication was our game-changer.

I remember when our servers kept hitting 100% load for no apparent reason. Checking system logs revealed the culprit: thousands of daily SSH password brute-force attempts flooding our authentication system. The moment we switched from password to key-based authentication and disabled password login entirely, our server load dropped like a rock.

Here's why this simple change makes such a dramatic difference.

Why SSH Key Authentication Drastically Reduces Server Load

The Brute-Force Killer

When you enable SSH password authentication, your server becomes like a house with an unlocked door on a busy street. Truth is, any SSH server exposed to the internet on port 22 receives countless brute-force attacks daily - some see thousands of login attempts every day.

Each authentication attempt consumes CPU and memory resources. When attackers use automated tools for brute-forcing, these requests create a flood of traffic that directly exhausts server resources.

With SSH key authentication, the story changes completely. Key authentication uses asymmetric encryption with typically long private keys (like 4096-bit), making them computationally impractical to crack. Attackers usually move on when they encounter this level of security because breaking it simply isn't worth the effort.

Streamlined Authentication Process

SSH key authentication isn't just more secure - it's more efficient too. With password authentication, the server maintains password verification mechanisms and handles the entire password input and validation process. Key authentication simplifies this: the client proves it possesses the private key, and the server simply verifies this using the stored public key.

This change reduces computational resources needed for authentication, especially noticeable during high-concurrency connections.

How Key Authentication Actually Works

SSH key pairs are generated through cryptographic algorithms, consisting of a public key and a private key.

  • Public Key: Placed on the server, acting like a public lock that anyone can see but cannot unlock
  • Private Key: Stored locally on the client, serving as the key that opens the lock - must be kept secure

When you connect to a server, it challenges you with a randomly generated message. You encrypt this message with your private key and send it back. The server then decrypts it using your stored public key for verification. If it matches, authentication succeeds. This process transmits no passwords, and your private key never leaves your local machine.

How to Configure SSH Key Authentication and Disable Passwords

Generate SSH Key Pair

On your local machine, use the ssh-keygen command to generate your key pair:


ssh-keygen -t rsa -b 4096

Here -t rsa specifies RSA key type, while -b 4096 sets the key length to 4096 bits - higher length means stronger security.

Upload Public Key to Server

  1. Log into your server, create the .ssh directory (if it doesn't exist), and set proper permissions:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
  1. Add your public key content (usually from id_rsa.pub file) to ~/.ssh/authorized_keys:

vim ~/.ssh/authorized_keys
  1. Set correct permissions for authorized_keys:

chmod 600 ~/.ssh/authorized_keys

Disable SSH Password Login

Edit the SSH server configuration file /etc/ssh/sshd_config:


vim /etc/ssh/sshd_config

Find and modify these lines:


PubkeyAuthentication yes
PasswordAuthentication no
PermitRootLogin without-password  # or use 'prohibit-password'

Restart SSH service to apply changes:


sudo systemctl restart sshd

Critical Warning: Before disabling password authentication, absolutely verify that your public key is properly installed and you can successfully login using key authentication! Otherwise, you might lock yourself out of the server.

Additional Tips to Reduce SSH-Related Load

Beyond switching to key authentication, here are more ways to optimize SSH performance:

Disable DNS Reverse Lookup

OpenSSH typically verifies client IP addresses by performing reverse DNS lookups, which can significantly slow down connections if DNS servers are slow or client IPs lack proper DNS records.

Add to /etc/ssh/sshd_config:


UseDNS no

Then restart SSH service - this noticeably speeds up connections.

Disable GSSAPI Authentication

GSSAPI authentication can cause issues when DNS resolution fails. By default, GSSAPIAuthentication is enabled on both server and client sides. If DNS services have problems, login processes wait until DNS queries timeout.

Set in /etc/ssh/sshd_config:


GSSAPIAuthentication no

Consider Changing SSH Port

While changing ports doesn't eliminate attacks, it dramatically reduces attack noise since most automated tools only scan default port 22. You can configure SSH to listen on a non-standard port.

Add to /etc/ssh/sshd_config:


Port 2222  # or any other non-standard port

Then connect using the specified port:


ssh -p 2222 username@server_ip_address

Key Management Best Practices

Secure Your Private Keys

Cloud platforms don't store your private keys - you typically get only one download opportunity. Store private keys in secure locations. Anyone with your private key can potentially decrypt your login credentials.

Use Strong Passphrases for Private Keys

When generating key pairs, you can set a passphrase for your private key. Even if someone steals your private key file, they still need to crack the passphrase to use it.

Regular Key Rotation

Establish a key rotation policy to periodically update SSH keys. Your rotation strategy should include key generation, distribution, testing, and revocation of old keys, ensuring business continuity during updates.

Conclusion

Since switching to SSH key authentication and disabling password logins, our server load dropped from consistently hitting 100% to single-digit percentages. CPU usage stabilized without those crazy fluctuations between 0% and 100%.

This isn't just a security improvement - it's a significant performance optimization. If you're struggling with high server load, check if you're still using SSH password authentication. Switching to key-based login might be the solution you've been searching for.

After all, in the world of server administration, security and performance are often two sides of the same coin.

Article by MGREI, please keep source when sharing:https://www.mgrei.com


This author has not provided a description.
Last updated on 2025-10-12