X
X

How to Secure SSH with Keys and Disable Passwords

HomepageArticlesLinux ServersHow to Secure SSH with Keys and Dis...

 

Secure Shell (SSH) is the standard method for remote access to Linux and Unix-based servers. However, relying on passwords alone makes your system vulnerable to brute-force attacks.

A more secure approach is to use SSH key-based authentication and disable password login entirely.


✅ Why Use SSH Keys?

  • Stronger than passwords (2048+ bit encryption)

  • Immune to brute-force and dictionary attacks

  • No need to remember or enter passwords

  • Can restrict key usage to specific users or IPs


???? Prerequisites

  • A Linux server with SSH access

  • A local Linux/macOS machine or a Windows client with an SSH tool (like PuTTY or Windows Terminal)


????️ Step-by-Step: Setup SSH Keys

???? 1. Generate SSH Key Pair (Client Side)

On your local machine:

bash
 
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • Save it as ~/.ssh/id_rsa (private) and id_rsa.pub (public)


???? 2. Copy Public Key to Server

Use the ssh-copy-id tool:

bash
 
ssh-copy-id user@your-server-ip

Or manually:

bash
 
cat ~/.ssh/id_rsa.pub | ssh user@your-server-ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Set correct permissions:

bash
 
ssh user@your-server-ip chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys

???? 3. Disable Password Authentication (Server Side)

Edit the SSH config file:

bash
 
sudo nano /etc/ssh/sshd_config

Find and change these lines:

nginx
 
PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no

Then restart SSH:

bash
 
sudo systemctl restart sshd

???? Test the Setup

Try reconnecting:

bash
 
ssh user@your-server-ip

If the private key is loaded, access should work without a password.


???? Tips

  • Use a passphrase for added protection on your private key

  • Backup your private key securely

  • Restrict IP addresses in ~/.ssh/authorized_keys if needed

  • Use tools like fail2ban for extra SSH protection


???? Final Thoughts

SSH keys significantly improve security over password-based logins. With minimal setup, you get stronger protection, easier automation, and peace of mind.

Need help setting up secure remote access across your servers? We can help you implement SSH best practices.


Top