Password-based SSH authentication leaves your VPS vulnerable to brute force attacks. SSH keys provide cryptographic authentication that eliminates this risk while simplifying your login workflow.
You will generate an SSH key pair, add the public key to your server and disable password authentication. Once complete, you connect to your VPS using your private key instead of a password.
SSH keys work in pairs. The private key stays on your local machine while the public key goes on your server. You need to generate this pair before configuring server access.
Linux and macOS users can generate keys using the built-in ssh-keygen command. Windows users should use PuTTYgen, which provides a graphical interface for key generation and management.
ssh-keygen -t rsa -b 4096
~/.ssh/id_rsa) or provide a custom path. The default location works for most users.~/.ssh/id_rsa.pub. You will copy this to your server in the next section.
Your server needs your public key stored in a specific location to authenticate your connection attempts. You will create the necessary directory structure and add your key to the authorized keys file.



mkdir -p ~/.ssh
chmod 700 ~/.ssh
This permission setting allows only the directory owner to read, write and execute files within it.
nano ~/.ssh/authorized_keys
Ctrl+X, then Y to confirm, then Enter to save the file and exit nano.
chmod 600 ~/.ssh/authorized_keys
Your server now accepts connections authenticated with your private key. Test this before disabling password authentication to confirm your key works correctly.
You need to verify that key-based authentication works before disabling password access. This prevents you from being locked out of your server if something goes wrong.
your-server-ip with your actual server address:ssh root@your-server-ip
root. You should connect without being asked for a password.If you connect successfully, your SSH key authentication is working correctly. You can now disable password authentication to secure your server.
Password authentication allows attackers to attempt brute force attacks against your server. Disabling it forces all connections to use SSH keys, which are practically impossible to crack through brute force.
nano /etc/ssh/sshd_config
Ctrl+W to open the search function in nano. Type PasswordAuthentication and press Enter.
PasswordAuthentication yes. Change yes to no. If the line starts with a hash symbol (#), remove it to uncomment the setting.Ctrl+X, then Y, then Enter to save the file and exit.
service sshd restart
Your server now rejects all password-based authentication attempts. Only users with the correct private key can connect.
Most SSH key issues stem from incorrect file permissions, malformed keys or configuration errors. These problems are usually quick to fix once identified.
This error appears when your server rejects your key. The most common causes are incorrect file permissions or a missing public key.
~/.ssh has permissions set to 700: chmod 700 ~/.ssh~/.ssh/authorized_keys has permissions set to 600: chmod 600 ~/.ssh/authorized_keysIf your connection asks for a password after adding your key, the server is not recognising your key authentication.
~/.ssh/authorized_keys matches your private keytail -f /var/log/auth.logIf you disabled password authentication before confirming that key authentication works, you need alternative access to restore password login.
/etc/ssh/sshd_config and change PasswordAuthentication back to yesservice sshd restartSSH keys form the foundation of secure server access, but additional hardening measures can further protect your VPS. Understanding these concepts helps you make informed decisions about your server security posture.
Key-based authentication eliminates the risk of password guessing attacks, but your private key becomes a single point of failure. Protecting this key with a strong passphrase adds a second authentication factor. Even if someone gains access to your key file, they cannot use it without the passphrase. The SSH Academy provides detailed guidance on key generation best practices and passphrase selection.
Regular security audits help identify potential vulnerabilities before they become problems. Review your authorized_keys file periodically to remove old or unused keys. Check your SSH logs for unusual connection attempts or patterns. Our VPS security guide covers these maintenance tasks in detail.
Your VPS now accepts only SSH key authentication, eliminating the risk of password-based attacks. You generated a key pair, added your public key to the server and disabled password authentication. Your private key provides secure access without transmitting passwords over the network.
Store your private key securely and never share it with anyone. Consider creating separate keys for different devices or team members. Our VPS hosting and Dedicated Cloud plans provide full root access for implementing these security configurations.
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting