SSH & ACCESS
June 24, 2026

How to Secure SSH with Keys and Disable Password Login

8 min read
Author
CloudStick Team
Server Infrastructure
Share this article
Secure SSH with Keys and Disable Password Login
CloudStick
Secure SSH with Keys

Why Password Authentication Is Risky

Password-based SSH authentication is the most common attack vector against Linux servers. Botnets continuously scan every public IP address for port 22 and attempt thousands of username/password combinations per minute — a technique called brute-force or credential stuffing. If your password is weak, guessable, or reused from another breach, your server is compromised.

Even strong passwords carry risk. They can be phished, leaked in data breaches, intercepted on a compromised machine, or found in shared credential files. A server with password login enabled is always one leaked credential away from full root access. The fix is simple: replace password authentication with SSH key authentication and disable passwords entirely.

Before you disable password login: Make absolutely sure your SSH key is installed, tested, and working. Disabling password auth without a working key will permanently lock you out of the server. Open a second SSH session using your key before closing the first.

How SSH Key Authentication Works

SSH key auth uses asymmetric cryptography. You generate a key pair: a private key that stays on your machine and a public key that gets placed on the server. When you connect, the server issues a cryptographic challenge that only the holder of the private key can solve. No password is ever transmitted.

This approach is fundamentally more secure than passwords for two reasons. First, the private key never leaves your machine — there is nothing to intercept over the network. Second, even if an attacker has your public key (which is meant to be public), they cannot derive the private key from it. Brute-forcing a 256-bit Ed25519 private key is computationally infeasible.

Generate Your SSH Key Pair

Run this on your local machine (not the server). Use Ed25519 — it is faster and more secure than the older RSA default:

# Generate an Ed25519 key pair
ssh-keygen -t ed25519 -C "your@email.com"
# The wizard prompts:
# Enter file in which to save the key (~/.ssh/id_ed25519):
# Enter passphrase (empty for no passphrase):
# Press Enter for default location
# Set a strong passphrase — this encrypts the private key
# Verify the files were created:
ls -la ~/.ssh/
# id_ed25519 ← private key (keep this secret)
# id_ed25519.pub ← public key (copy this to server)

A passphrase on your private key adds a second layer of protection. Even if someone steals your key file, they still cannot use it without the passphrase. Use ssh-agent to avoid typing the passphrase on every connection.

Copy Your Public Key to the Server

The easiest method is ssh-copy-id, which handles the correct permissions automatically:

# Method 1: ssh-copy-id (recommended)
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your-server-ip
# Method 2: Manual (if ssh-copy-id is unavailable)
cat ~/.ssh/id_ed25519.pub | ssh user@your-server-ip \
"mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
# Verify key-based login works BEFORE disabling passwords:
ssh -i ~/.ssh/id_ed25519 user@your-server-ip
# Check authorized_keys on the server:
cat ~/.ssh/authorized_keys
ls -la ~/.ssh/
# drwx------ .ssh (700)
# -rw------- authorized_keys (600)

Permissions matter. SSH will silently reject keys if ~/.ssh is world-writable or authorized_keys has permissions wider than 600. This is one of the most common reasons key auth mysteriously fails.

Disable Password Login in sshd_config

Once your key-based login is confirmed working, edit the SSH daemon configuration:

# Open the SSH daemon config
sudo nano /etc/ssh/sshd_config
# Find and set these directives:
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PermitRootLogin prohibit-password
ChallengeResponseAuthentication no
UsePAM yes
# Test the config before restarting:
sudo sshd -t
# Apply changes:
sudo systemctl reload sshd
Do not close your current session after reloading sshd. Open a new terminal window and test that key-based login works. Only after a successful new connection should you trust the config is correct.

Setting PermitRootLogin prohibit-password rather than no allows emergency root access via key if your non-root user is accidentally locked out. In most production environments, disabling root login entirely is preferable.

CloudStick SSH Key Management

CloudStick installs with password authentication already disabled and SSH keys configured during server provisioning. For servers you manage through CloudStick, the SSH Keys section in the server panel lets you add, revoke, and audit authorized keys for any system user without touching the command line.

The SSH Vault feature stores key references centrally, so when you need to grant or revoke access for a team member across multiple servers, you do it in one place. For existing servers you bring into CloudStick, the SSH Settings Management section (available on Basic plan and above) lets you review and harden your sshd_config settings from the dashboard without direct command-line access.

Leave a comment
Full Name
Email Address
Message
On this page

We use cookies to improve your experience

CloudStick uses cookies to personalise content, analyse traffic and keep you signed in. Cookie Policy · Terms of Service

Manage cookies