SSH key authentication: log in without a password
Install your public SSH key on a server, log in with it, and then turn off password logins. Covers ssh-copy-id, manual install, Windows, ssh-agent and safe testing.
On this page
With SSH key authentication you log in with a key file instead of a password. Your private key stays on your computer, and the matching public key is added to the server. Keys cannot be guessed the way passwords can, so they stop brute-force login attempts. If you do not have a key yet, create one first with Generate SSH keys.
How key login works
- You add your public key (the
.pubfile) to~/.ssh/authorized_keyson the server. - When you connect, the server asks your computer to prove it holds the matching private key.
- Your SSH client signs the request with the private key. The private key never leaves your computer.
Where you can use SSH keys
| Service | SSH access | Notes |
|---|---|---|
| Cloud VPS and dedicated servers | Yes, full root access | Credentials arrive by encrypted email or in CustomerPanel. SSH keys and custom usernames are available on request when the server is set up. |
| Managed Business hosting | Yes | Add your key for the hosting account, then connect as that account's user. |
| Shared hosting | No | Shared plans do not include SSH. Use FTP with TLS or the cPanel File Manager. See FTP vs SFTP. |
Install your public key
The easy way, with ssh-copy-id (macOS and Linux). It logs in with your password once and adds the key for you:
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@your-server-ip
# custom SSH port
ssh-copy-id -i ~/.ssh/id_ed25519.pub -p 2222 root@your-server-ip
By hand, if ssh-copy-id is not available. Log in with your password, then run:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "ssh-ed25519 AAAA...your-public-key... you@laptop" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Paste the whole public key on one line: it starts with ssh-ed25519 or ssh-rsa and ends with a comment such as your email address.
From Windows
Windows 10 and 11 include OpenSSH. In PowerShell, ssh-copy-id is not available, so pipe the key instead:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@your-server-ip "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
If you use PuTTY, load your private key (.ppk) under Connection → SSH → Auth → Credentials. PuTTYgen converts between PuTTY and OpenSSH key formats.
Test the key login
Keep your current session open and test from a new terminal window:
ssh -i ~/.ssh/id_ed25519 root@your-server-ip
# shows which keys are tried and why one is rejected
ssh -v -i ~/.ssh/id_ed25519 root@your-server-ip
If you are asked for the key's passphrase (not the server password), the key login works.
Stop retyping the passphrase
Load the key into ssh-agent once per session:
# macOS and Linux
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
# Windows PowerShell (as administrator, once)
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $env:USERPROFILE\.ssh\id_ed25519
Add a host entry to ~/.ssh/config so ssh myserver picks the right user, port and key. See Generate SSH keys for an example.
Turn off password logins
Only after the key login works, on a VPS or dedicated server you can stop password logins completely:
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
# check the configuration, then reload SSH
sshd -t && systemctl reload sshd # AlmaLinux, Rocky Linux, CloudLinux
sshd -t && systemctl reload ssh # Debian, Ubuntu
Open a new session and log in with the key before you close the old one. Some systems also have files in /etc/ssh/sshd_config.d/ that turn passwords back on, so check them too. If you lock yourself out, open a ticket, or use KVM/IPMI console access on a dedicated server where you have it. See Manage SSH keys on your VPS.
Troubleshooting
"Permission denied (publickey)": the server did not accept any key. Check that the public key is on one line in authorized_keys, that you log in as the user whose file holds the key, and that you pass the right private key with -i.
Still asked for the server password: SSH ignores authorized_keys when permissions are too open. Run chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys, and make sure the files belong to that user.
"UNPROTECTED PRIVATE KEY FILE": your private key is readable by others on your computer. Run chmod 600 ~/.ssh/id_ed25519.
Too many authentication failures: your agent offers many keys and the server stops after a few. Add IdentitiesOnly yes and the right IdentityFile to the host in ~/.ssh/config.
FAQ
Related: Generate SSH keys | Manage SSH keys on your VPS | SSH hardening | SSH access basics
Need a developer-friendly server?
Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.





















