SSH Keys for Beginners: Set Up Key Login on cPanel and a VPS
Every server that accepts SSH logins with a password is a target for bots that try thousands of passwords a day. SSH keys remove that risk. Instead of typing a password, your computer proves its identity with a cryptographic key pair, and nothing guessable ever crosses the network.
This guide is for beginners. You will create a key, add it to a cPanel account and to a VPS, test it, and then switch off password logins on the VPS without locking yourself out.
How key login works
An SSH key is a pair of files:
- The private key stays on your computer. Treat it like the key to your house: never email it, upload it or paste it anywhere.
- The public key ends in
.puband is safe to share. You copy it to every server you want to log in to.
When you connect, the server checks that your computer holds the private key that matches a public key it trusts. A passphrase on the private key adds a second layer: even if someone copies the file, they cannot use it without the passphrase.
If SSH itself is new to you, start with our SSH basics guide and come back here.
Step 1: Generate a key on your computer
macOS, Linux and current versions of Windows 10 and 11 include OpenSSH, so the same command works in Terminal or PowerShell:
ssh-keygen -t ed25519 -C "laptop-2026"
- Press Enter to accept the default location (
~/.ssh/id_ed25519, orC:\Users\NAME\.ssh\id_ed25519on Windows). - Enter a passphrase when asked. Choose something long that you can remember.
- Show the public key so you can copy it:
cat ~/.ssh/id_ed25519.pub
The output is one line starting with ssh-ed25519. That line is what you give to servers. The comment at the end (laptop-2026) helps you recognize the key later.
To avoid typing the passphrase every time, load the key into the SSH agent once per session with ssh-add ~/.ssh/id_ed25519. On macOS, ssh-add --apple-use-keychain ~/.ssh/id_ed25519 stores it in the Keychain. If you use PuTTY on Windows, PuTTYgen can import this key and save it in PuTTY's .ppk format.
Step 2: Add the key to a cPanel account
- Log in to cPanel and open SSH Access in the Security section, then click Manage SSH Keys.
- Click Import Key. Give it a name, paste your public key into the Public Key field and leave the private key field empty. Click Import.
- Go back to the key list. New keys appear as not authorized. Click Manage next to your key, then Authorize.
- Connect from your computer. Your host will tell you the SSH port if it is not 22:
ssh -p 22 USER@example.com
cPanel can also generate a key pair for you, but then the private key is created on the server and has to be downloaded. Generating it on your own computer is safer because the private key never exists anywhere else. If you do not see SSH Access in cPanel, shell access is not enabled for your account, so ask your host.
Step 3: Add the key to a VPS
On macOS and Linux, ssh-copy-id copies the key and sets the right permissions. You will type the server password one last time:
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@203.0.113.10
Windows does not include ssh-copy-id. In PowerShell, this does the same job:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Replace deploy with your user and the IP with your server's address. Using a regular user with sudo rights instead of root is good practice, as explained in our article on sudo and user management.
Step 4: Test the key login
Open a new terminal and connect. If you set a passphrase, SSH asks for the passphrase of the key, not the server password. That is how you know the key is used:
ssh -v deploy@203.0.113.10
Near the end of the verbose output you should see a line saying you authenticated using "publickey". To save typing, add an entry to ~/.ssh/config on your computer:
Host myvps
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519
Now ssh myvps is enough.
Step 5: Disable password logins on the VPS
Only do this after Step 4 works. Keep your current SSH session open the whole time, so you can undo a mistake.
- Check for existing settings in the drop-in folder. Some cloud images add a file that turns passwords back on:
grep -ri passwordauthentication /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ - Create a file that loads first. OpenSSH uses the first value it reads for each setting, and files in
sshd_config.dload in alphabetical order:sudo nano /etc/ssh/sshd_config.d/00-keys-only.conf - Add these lines and save:
PasswordAuthentication no KbdInteractiveAuthentication no PermitRootLogin prohibit-password - Check the configuration for errors. No output means it is valid:
sudo sshd -t - Restart the SSH service. On Ubuntu and Debian it is called
ssh, on AlmaLinux and Rocky Linuxsshd:sudo systemctl restart ssh - Confirm the settings the server is actually using:
sudo sshd -T | grep -E 'passwordauthentication|kbdinteractiveauthentication|permitrootlogin' - From a new terminal, check that
ssh myvpsstill logs you in with the key. Then confirm that password login is refused:
This command should end with "Permission denied (publickey)".ssh -o PubkeyAuthentication=no deploy@203.0.113.10
PermitRootLogin prohibit-password still allows root with a key. Once your sudo user works, you can set it to no for a stricter setup.
Common problems and fixes
| Message | Usual cause | Fix |
|---|---|---|
| Permission denied (publickey) | Key not on the server, wrong user, or key not authorized in cPanel | Check the username, then the key list in cPanel or ~/.ssh/authorized_keys on the VPS |
| Key ignored although it is in authorized_keys | Permissions too open on the server | Run chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys |
| UNPROTECTED PRIVATE KEY FILE | Private key readable by other users on your computer | Run chmod 600 ~/.ssh/id_ed25519 |
| Too many authentication failures | The agent offers many keys before the right one | Add IdentitiesOnly yes to the host entry in ~/.ssh/config |
| REMOTE HOST IDENTIFICATION HAS CHANGED | The server was reinstalled, or something is intercepting the connection | If you reinstalled it, run ssh-keygen -R 203.0.113.10; otherwise stop and investigate |
When something fails, ssh -v shows which keys your computer offered and where the process stopped. On the VPS, the SSH log (sudo journalctl -u ssh on Ubuntu) shows why a login was rejected.
Keep your keys safe
- Use a passphrase on every private key, especially on laptops.
- Create one key per device. If a laptop is lost, you remove only that key from your servers.
- Review
~/.ssh/authorized_keyson each VPS and the key list in cPanel from time to time, and delete keys for old devices and former team members. - Back up your private keys in an encrypted password manager or on encrypted storage.
- Do not reuse the same deploy key for many unrelated services.
Frequently asked questions
Should I use Ed25519 or RSA?
Ed25519 for new keys. It is short, fast and supported by all current SSH servers, cPanel and code hosts such as GitHub. Use RSA with 4096 bits only for old systems that do not accept Ed25519.
What if I lose my private key after disabling passwords?
You need another way in, such as a second authorized key or the web console or rescue mode that many VPS providers offer. On cPanel, log in to the panel with your password and import a new key. Adding a second key from another device in advance avoids the problem.
Is a key without a passphrase ever acceptable?
For automation, yes: a deploy script or backup job cannot type a passphrase. Give such keys a single purpose, store them only on the machine that needs them, and never use them for your personal logins.
Can I use the same key for several servers?
Yes. The public key can go on as many servers as you like. What matters is that the private key stays on your devices.
Do I still need a firewall and brute-force protection?
Yes. Keys stop password guessing, but a firewall limits what is reachable at all, and blocking repeat offenders keeps logs clean. See our guides on firewall setup with ufw and brute force attacks.
Hostinq.com KVM VPS plans come with full root access, NVMe storage and IPv4 plus IPv6, so you can apply every step above from the first login. Cloud VPS plans start at $24.80 a month in Germany.