SSH Key - Still asking for password and passphrase
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If SSH keeps asking for a password or passphrase after you have set up key-based authentication, the problem is almost always one of four things: the SSH agent does not have your key loaded, the file permissions on the remote server are too open, the server's sshd_config does not allow public key authentication, or you are connecting with the wrong key. The fix usually takes less than five minutes once you identify which of these is the cause.
Quick Diagnostic: Use Verbose Mode
The single most useful troubleshooting step is connecting with verbose output. This shows exactly what happens during the authentication handshake:
Look for these lines in the output:
If you instead see:
That tells you the client could not find or offer the correct key and fell back to password authentication.
Fix 1: Add Your Key to the SSH Agent
The SSH agent holds your private keys in memory so you do not have to enter the passphrase every time. If the key is not loaded, SSH cannot offer it to the server.
If ssh-add -l returns "Could not open a connection to your authentication agent," the agent is not running:
To make the agent start automatically on login, add the eval line to your ~/.bashrc, ~/.zshrc, or equivalent shell config file.
Fix 2: Fix File Permissions
SSH is strict about file permissions. If any SSH-related file or directory has permissions that are too open, SSH silently refuses to use the key and falls back to password authentication. No error is shown on the client side, which makes this a common source of confusion.
On the remote server:
On the local machine:
Here is the complete permissions table:
| Path | Required Permission | Why |
~ (home directory) | 755 or stricter | SSH checks that group/other cannot write to home |
~/.ssh/ | 700 | Only the owner should access this directory |
~/.ssh/authorized_keys | 600 | Only the owner should read/write |
~/.ssh/id_ed25519 (private key) | 600 | Private key must not be readable by others |
~/.ssh/id_ed25519.pub (public key) | 644 | Public key is not sensitive |
~/.ssh/config | 600 | May contain sensitive hostnames and settings |
A common mistake: using chmod 777 on the home directory for some other reason. SSH sees that and refuses to trust authorized_keys in that directory.
Fix 3: Verify Server Configuration
The SSH server must be configured to accept public key authentication. Check /etc/ssh/sshd_config on the remote server:
The expected values:
If PubkeyAuthentication is set to no, change it to yes and restart the SSH daemon:
Once key authentication is working, you can optionally disable password authentication entirely for better security:
Fix 4: Ensure the Correct Key Is Being Used
If you have multiple SSH keys, SSH may offer the wrong one. Use ~/.ssh/config to map specific keys to specific hosts:
The IdentitiesOnly yes directive is important. Without it, SSH tries all keys loaded in the agent before using the specified IdentityFile. If the agent has many keys, the server may reject the connection after too many failed attempts (typically 3 or 6).
Fix 5: Verify authorized_keys on the Server
Make sure your public key is correctly added to the remote server's ~/.ssh/authorized_keys file:
The output looks like:
This entire line (including the key type and comment) must be a single line in ~/.ssh/authorized_keys on the server. Common mistakes:
- The key was split across multiple lines during copy-paste.
- The key was added to the wrong user's
authorized_keys. - There are trailing whitespace or invisible characters.
The simplest way to copy a key to a server is:
This command handles creating the .ssh directory, setting permissions, and appending the key correctly.
Passphrase vs Password
These are two different things, and the prompts look similar but mean different things:
| Prompt | Source | Meaning |
Enter passphrase for key '/home/user/.ssh/id_ed25519': | Local SSH client | Your private key is encrypted with a passphrase. Enter it to decrypt the key. |
[email protected]'s password: | Remote SSH server | Key authentication failed. The server is asking for the account password. |
If you see the passphrase prompt, key authentication is working correctly. The passphrase decrypts your local private key. To avoid typing it every time, load the key into the SSH agent (see Fix 1).
If you see the password prompt, key authentication failed entirely. Check permissions, server config, and whether the correct key was offered (Fixes 2-5).
SELinux and Security Contexts
On systems running SELinux (RHEL, CentOS, Fedora), correct file permissions alone may not be enough. SELinux security contexts must also be correct:
If the authorized_keys file was created or copied in an unusual way, its SELinux context may be wrong, causing SSH to silently reject it even though UNIX permissions are correct.
Common Pitfalls
Not starting the SSH agent. On many systems, the SSH agent does not start automatically. If ssh-add -l returns "Could not open a connection to your authentication agent," the agent is not running. Start it with eval "$(ssh-agent -s)".
Using chmod 777 or chmod 775 on the home directory. SSH requires that the home directory, .ssh directory, and authorized_keys file are not writable by group or other users. This is a security requirement, not a bug.
Offering too many keys from the agent. If you have 10+ keys loaded in the SSH agent and the server's MaxAuthTries is set to 6 (the default), SSH exhausts its attempts before reaching the correct key. Use IdentitiesOnly yes in your SSH config to send only the specified key.
Copying the private key instead of the public key to authorized_keys. The authorized_keys file should contain the .pub file content (starting with ssh-ed25519 or ssh-rsa), not the private key (which starts with -----BEGIN OPENSSH PRIVATE KEY-----).
Not restarting sshd after config changes. Changes to /etc/ssh/sshd_config do not take effect until the SSH daemon is restarted or reloaded. Use sudo systemctl restart sshd.
Using RSA keys that are too short. OpenSSH 8.8+ disables RSA-SHA1 signatures by default. If you are using an older RSA key (typically 1024-bit), generate a new Ed25519 key instead: ssh-keygen -t ed25519 -C "[email protected]".
Summary
- Use
ssh -vvvto see exactly where authentication fails. - Load your key into the SSH agent with
ssh-addto avoid passphrase prompts on every connection. - Fix permissions:
700for~/.ssh,600forauthorized_keysand private keys, and755or stricter for the home directory. - Verify
PubkeyAuthentication yesin the server's/etc/ssh/sshd_config. - Use
~/.ssh/configwithIdentityFileandIdentitiesOnly yesto control which key is offered to which host. - Distinguish between the passphrase prompt (local key decryption, working as intended) and the password prompt (key auth failed, needs debugging).
- Use
ssh-copy-idto correctly install your public key on remote servers.
Related reading
- SSH Key - Still asking for password and passphrase
- ssh remote host identification has changed
- SSL and cert keystore
- SSL Certificate added but shows Kubernetes Ingress controller fake certificate
- SSL CERTIFICATE_VERIFY_FAILED in aws cli
- SSL InsecurePlatform error when using Requests package
- SSL certificate rejected trying to access GitHub over HTTPS behind firewall
- SSL certificates from Let’s Encrypt in your Kubernetes Ingress via cert-manager

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.