Security

SSH Passwordless Login: How Key-Based Authentication Works

7 min read
By
SSH Passwordless Login: How Key-Based Authentication Works

NovelCrypt

SSH passwordless login is one of the most practical applications of public-key cryptography. Instead of typing a password every time you connect to a server, you authenticate with a cryptographic key pair. The server verifies your identity through a challenge-response handshake that proves you hold the private key, without the private key ever being transmitted. This is both more convenient and more secure than password authentication.

What SSH Passwordless Login Is

SSH (Secure Shell) is a protocol for secure remote access to servers and other network devices. By default, SSH supports two authentication methods: password authentication and public-key authentication. Passwordless login refers to using public-key authentication exclusively, so you never need to type (or even have) a password on the server.

The "passwordless" part refers to the server password. Your private key may still be protected by a passphrase locally — this is a separate password that encrypts the private key file on your disk. The passphrase is never sent to the server. It exists solely to protect your private key if your local machine is compromised.

How SSH Key-Based Authentication Works

The authentication process is a cryptographic challenge-response handshake. The server sends a challenge that can only be answered correctly by someone holding the private key. Here is the step-by-step flow:

### Setup Phase (Done Once)

1. You generate a key pair on your local machine using ssh-keygen. This creates a private key (typically in ~/.ssh/id_ed25519 or ~/.ssh/id_rsa) and a public key (~/.ssh/id_ed25519.pub or ~/.ssh/id_rsa.pub). 2. You copy the public key to the server and append it to the ~/.ssh/authorized_keys file for your user account. The ssh-copy-id tool automates this. 3. The server now has your public key. Your private key remains on your local machine only.

### Authentication Phase (Each Connection)

1. You initiate an SSH connection: ssh user@server. 2. The SSH client and server negotiate the encryption algorithms and establish a secure (encrypted) channel for the session. This uses asymmetric encryption — the same category as RSA — for the initial key exchange. Read our symmetric vs asymmetric encryption guide for the broader context. 3. The server sends a challenge: a random number (nonce), encrypted with your public key (or structured so that only your private key can produce the correct response, depending on the algorithm). 4. Your SSH client uses your private key to decrypt or sign the challenge. If your private key has a passphrase, the client prompts you for it at this point (or retrieves it from the SSH agent). 5. The client sends the response back to the server. 6. The server verifies the response using your public key from authorized_keys. If the response is correct, the server knows you hold the private key and grants access. 7. No password was sent. The private key was never transmitted. The challenge is unique to this session, so a captured response cannot be replayed.

### The Cryptographic Detail

For RSA keys, the challenge-response works through signature: the client signs the session identifier with the private key, and the server verifies the signature with the public key. For Ed25519, the same principle applies using the EdDSA signature scheme. For ECDSA, the client produces an ECDSA signature that the server verifies.

In all cases, the security property is the same: the server proves that the connecting client holds the private key corresponding to the authorized public key, without the private key being sent. This is the fundamental property of asymmetric cryptography — the same property that powers digital signatures and RSA encryption.

Why Key-Based Authentication Is More Secure Than Passwords

### No Brute-Force Over the Network

Password authentication allows an attacker to try many passwords against the SSH server. Even with rate limiting and fail2ban, a determined attacker can attempt thousands of passwords over time. With key-based authentication, there is nothing to guess. The challenge is a random nonce for each session, and the correct response requires the private key, which is a 256-bit (Ed25519) or 2048+ bit (RSA) value. Guessing the private key is computationally impossible.

### No Credential Stuffing

Credential stuffing — trying username/password pairs leaked from other breaches — does not work with key-based authentication because there is no password on the server. A breach of another service that exposed your password does not compromise your SSH access.

### No Password Transmission

With password authentication, the password is sent through the encrypted SSH channel to the server. If the server is compromised (a man-in-the-middle attack during the first connection, or a compromised server), the password can be captured. With key-based authentication, the private key never leaves your machine. A compromised server gets your public key (which is not secret) and the challenge-response (which is session-specific and cannot be reused).

### Stronger Key Material

A good password has perhaps 60-80 bits of entropy. A 256-bit Ed25519 key has 128 bits of security. A 3072-bit RSA key has 128 bits of security. The key is orders of magnitude harder to brute-force than any password a human could remember.

What Algorithms SSH Uses

SSH supports several key types. The choice matters for both security and performance.

| Algorithm | Key Size | Security Level | Recommendation | | --- | --- | --- | --- | | Ed25519 | 256 bits (fixed) | 128 bits | Recommended for new keys | | RSA | 2048+ bits | 112+ bits | Use 3072+ bits if Ed25519 unavailable | | ECDSA | 256, 384, 521 bits | 128, 192, 256 bits | Usable, but curve trust concerns | | DSA | 1024 bits (max) | 80 bits | Deprecated, do not use |

### Ed25519

Ed25519 is the recommended SSH key algorithm. It is based on Edwards-curve Digital Signature Algorithm (EdDSA) using Curve25519. Ed25519 keys are small (68 bytes encoded), signatures are small (64 bytes), and signing and verification are fast. Ed25519 was designed to avoid implementation pitfalls that affect other algorithms — it is deterministic (no nonce to get wrong), resistant to side-channel attacks, and does not depend on a random number generator at signing time.

Generate an Ed25519 key: ssh-keygen -t ed25519

### RSA

RSA is the legacy fallback. If you are connecting to older servers that do not support Ed25519 (OpenSSH versions before 6.5, released in 2014), RSA is the universal option. Use at least 3072 bits for new keys. RSA-2048 is still acceptable for short-term use but NIST recommends 3072 bits for security beyond 2030.

Generate an RSA key: ssh-keygen -t rsa -b 3072

### ECDSA

ECDSA is supported by modern SSH but is less commonly used than Ed25519 or RSA. The concern with ECDSA is that the NIST curves (P-256, P-384, P-521) have parameters that were generated by NIST without a transparent process, leading to (unproven but persistent) concerns about potential backdoors. Ed25519 avoids this by using Curve25519, which has a transparent derivation.

### DSA

DSA (Digital Signature Algorithm) is deprecated in OpenSSH. It is limited to 1024-bit keys, which provide only 80 bits of security. OpenSSH 7.0 (2015) disabled DSA by default. Do not generate new DSA keys and migrate any existing DSA keys to Ed25519.

How to Set Up SSH Keys

### Step 1: Generate a Key Pair

ssh-keygen -t ed25519 -C "your_email@example.com"

This creates: - ~/.ssh/id_ed25519 (private key) - ~/.ssh/id_ed25519.pub (public key)

You will be prompted for a passphrase. Use a strong passphrase — it encrypts the private key file so that if someone steals the file, they cannot use it without the passphrase.

### Step 2: Copy the Public Key to the Server

ssh-copy-id user@server

This appends your public key to ~/.ssh/authorized_keys on the server for the specified user. If ssh-copy-id is not available, you can do it manually:

cat ~/.ssh/id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

### Step 3: Test the Connection

ssh user@server

You should connect without a password prompt (though you may be prompted for your private key passphrase if you set one). If you are still prompted for a password, check that: - The server authorized_keys file contains your public key. - File permissions are correct: ~/.ssh should be 700, authorized_keys should be 600. - The server allows public-key authentication (PubkeyAuthentication yes in sshd_config).

### Step 4: Disable Password Authentication

Once key-based authentication is working, disable password authentication on the server. Edit /etc/ssh/sshd_config:

PasswordAuthentication no PubkeyAuthentication yes

Then restart the SSH service: sudo systemctl restart sshd

This is the step that makes the setup truly secure. Key-based authentication alone does not prevent password brute-force attacks if password authentication is still enabled. You must disable it.

SSH Agent and Key Passphrase

The SSH agent is a program that holds your decrypted private keys in memory so you do not have to type the passphrase for every connection. You type the passphrase once when adding the key to the agent, and subsequent SSH connections use the agent without prompting.

Start the agent: eval "$(ssh-agent -s)"

Add your key: ssh-add ~/.ssh/id_ed25519

The agent stores the decrypted key in memory for the duration of your session. When you log out or reboot, the agent is cleared and you need to enter the passphrase again.

On macOS, the SSH agent integrates with the Keychain, so your passphrase is stored in the Keychain and automatically entered when you start a new session. On Linux, you can use keychain (a wrapper that persists the agent across sessions) or gnome-keyring.

Common Issues and Troubleshooting

### Permission Denied (publickey)

The most common error. Check: - authorized_keys on the server contains your public key (check with: ssh user@server cat ~/.ssh/authorized_keys — but you will need password access or console access to do this). - File permissions: ~/.ssh is 700, authorized_keys is 600, private key on client is 600. - The key you are offering matches the key in authorized_keys (compare fingerprints: ssh-keygen -lf ~/.ssh/id_ed25519.pub).

### Server Ignores the Key

Some servers have restrictive settings: - AuthorizedKeysFile may point to a non-standard location. - The user account may be locked (no valid shell, or password locked). - AllowUsers or AllowGroups in sshd_config may not include your user.

### Connection Works but Password Is Still Accepted

You copied the key successfully but did not disable password authentication. Edit sshd_config, set PasswordAuthentication no, and restart sshd. Until you do this, the server is still vulnerable to password brute-force attacks.

### Key Works from One Client but Not Another

Different keys. Each client machine has its own key pair. You need to copy each client public key to the server authorized_keys file. Alternatively, you can copy the same private key to multiple machines, but this increases the risk surface — if one machine is compromised, the key is compromised everywhere it was copied.

The Bottom Line

SSH passwordless login is one of the highest-value security improvements you can make to a server. It replaces guessable passwords with unbreakable cryptographic keys, eliminates credential stuffing and brute-force attacks, and makes daily work more convenient. Use Ed25519 keys for new setups, protect your private key with a strong passphrase, use an SSH agent for convenience, and always disable password authentication on the server after confirming key-based login works. The underlying cryptography — asymmetric key pairs and challenge-response handshakes — is the same foundation that powers RSA encryption, token-based authentication, and every modern secure communication system.

Frequently Asked Questions

Is SSH passwordless login secure?

Yes, when set up correctly. SSH key-based authentication is more secure than passwords because the private key never traverses the network, keys are typically 2048+ bits (far harder to brute-force than a password), and key-based auth is immune to credential stuffing. Security depends on protecting the private key (strong passphrase, restricted file permissions, never copying it to untrusted machines) and disabling password authentication on the server.

What algorithm should I use for SSH keys?

Ed25519 is the recommended choice for new SSH keys. It is fast, uses small keys, and is based on modern elliptic curve cryptography. If Ed25519 is not available (older servers), RSA with at least 3072 bits is the fallback. ECDSA is usable but has concerns about curve parameter trust. Avoid DSA entirely — it is deprecated and limited to 1024 bits.

How do I set up SSH passwordless login?

Generate a key pair with ssh-keygen (ssh-keygen -t ed25519), then copy the public key to the server with ssh-copy-id (ssh-copy-id user@host). This appends your public key to the server authorized_keys file. Test the connection (ssh user@host). If it works without a password prompt, disable password authentication in sshd_config (PasswordAuthentication no) and restart the SSH service.

Can SSH keys be hacked?

The private key itself cannot be practically brute-forced — a 256-bit Ed25519 key or 3072-bit RSA key is computationally infeasible to crack. However, SSH keys can be compromised through other means: a stolen unencrypted private key file, a weak passphrase on the key, a compromised client machine, or a server-side authorized_keys tampering. The key is only as secure as the machine it lives on and the passphrase protecting it.

Explore the Share Password Securely: Try it now

Try NovelCrypt Tools

Experience military-grade encryption for your sensitive data. Create self-destructing messages, encrypt files, or explore our experimental lab tools.

Explore NovelCrypt