UnderHost
Knowledgebase Docs

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

  1. You add your public key (the .pub file) to ~/.ssh/authorized_keys on the server.
  2. When you connect, the server asks your computer to prove it holds the matching private key.
  3. Your SSH client signs the request with the private key. The private key never leaves your computer.

Where you can use SSH keys

ServiceSSH accessNotes
Cloud VPS and dedicated serversYes, full root accessCredentials arrive by encrypted email or in CustomerPanel. SSH keys and custom usernames are available on request when the server is set up.
Managed Business hostingYesAdd your key for the hosting account, then connect as that account's user.
Shared hostingNoShared 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:

terminal
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:

on the server
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:

PowerShell
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:

terminal
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:

terminal
# 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:

/etc/ssh/sshd_config
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
terminal
# check the configuration, then reload SSH
sshd -t && systemctl reload sshd    # AlmaLinux, Rocky Linux, CloudLinux
sshd -t && systemctl reload ssh     # Debian, Ubuntu
Test before you close your session

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

No. UnderHost shared hosting plans do not include SSH access. Managed Business hosting, Cloud VPS and dedicated servers do.
Yes. SSH keys and custom usernames are available on request for VPS and dedicated servers. Send your public key, never the private key.
Yes, for keys on a laptop or desktop. If the key file is stolen, the passphrase still protects it. Use ssh-agent so you type it once per session.
Yes. Add the same public key to each server. Use separate keys for separate people, so you can remove one person's access without affecting others.

Related: Generate SSH keys | Manage SSH keys on your VPS | SSH hardening | SSH access basics

Was this article helpful?

Need a developer-friendly server?

Use an UnderHost Cloud VPS for SSH, Git, Node.js, Python, Laravel, Docker, cron, and custom development workflows.

Related articles

Back to Developer Tools