What Is an SSH Key? Secure VPS Login Without a Password
Create SSH keys on Windows, Linux, and macOS, add the public key to a VPS, configure an SSH alias and permissions, and fix publickey errors safely.
Article by Phạm Minh Thiện
Front-end developer working directly with Next.js, NestJS, Docker, Nginx, and Ubuntu VPS deployments.
Reviewed on 7/21/2026.
Table of contents
SSH key authentication uses a private key on your computer and a matching public key on the server. The private key proves ownership without sending a reusable password over the connection.
Generate a key
Ed25519 is a good modern default:
ssh-keygen -t ed25519 -C "my-vps"
In Windows PowerShell, the same OpenSSH command works when the Windows OpenSSH client is installed. Accept the default path or choose a named key. Protect it with a passphrase.
The files are normally:
- private key:
~/.ssh/id_ed25519; - public key:
~/.ssh/id_ed25519.pub.
Share only the .pub file. Never paste the private key into GitHub issues, chat, or server configuration.
Add the public key to the VPS
If password login is still enabled, use:
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@203.0.113.10
On Windows or when ssh-copy-id is unavailable, append the public key to the server user’s ~/.ssh/authorized_keys through your provider’s console or an existing session.
The server should have:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R "$USER":"$USER" ~/.ssh
Test before disabling passwords
Open a new terminal and use the key explicitly:
ssh -i ~/.ssh/id_ed25519 deploy@203.0.113.10
Keep the original session open until the new login works. Only then consider PasswordAuthentication no and PermitRootLogin no in sshd_config; validate with sshd -t before reloading SSH.
Use an SSH config alias
Create ~/.ssh/config:
Host my-vps
HostName 203.0.113.10
User deploy
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
Then connect with:
ssh my-vps
IdentitiesOnly yes prevents an SSH agent with many keys from offering unrelated identities.
Use ssh-agent for passphrases
An agent can keep the decrypted key available for the current session:
ssh-add ~/.ssh/id_ed25519
ssh-add -l
Prefer the operating system’s protected credential store where available.
Troubleshooting
Permission denied (publickey): confirm the user, key path, andauthorized_keyspermissions.- The server ignores the key: check
PubkeyAuthenticationand the SSH service log. - Too many authentication failures: use
IdentitiesOnly yesorssh -o IdentitiesOnly=yes -i .... Host key has changed: verify the server fingerprint before modifyingknown_hosts.
If a private key is lost, create a new key pair and add its public key through an existing session or the provider console. If a private key may have leaked, remove its public key from every server and rotate related credentials immediately.
Continue reading
Related articles
Safely Fix SSH Permission Denied and Host Key Changed Errors
Check the correct SSH user, private key, authorized_keys, file permissions, and server fingerprint before repairing publickey or known_hosts errors.
Read article →What to Do After Buying an Ubuntu VPS: 20 Production Setup Steps
A practical Ubuntu VPS checklist covering a sudo user, SSH keys, UFW, security updates, swap, backups, monitoring, and final checks before deployment.
Read article →GitHub Actions CI/CD: Automatically Deploy Node.js to a VPS
Create a secure GitHub Actions pipeline that builds, tests, and deploys Node.js to a VPS over SSH with secrets, health checks, concurrency, and rollback.
Read article →