Using SSH keys is one of the most secure and efficient ways to connect to a VPS. Instead of entering a password every time, you can authenticate using a private/public key pair. In this guide, we’ll walk you through uploading your SSH public key to an existing VPS to enable secure, passwordless login.
Before you begin, ensure the following:
You already have access to your VPS via username and password.
You have an SSH key pair generated on your local machine.
ssh is installed on your local machine (Linux, macOS, or Windows with WSL or PuTTY/Pageant).
On your local machine, run:
Check if you have a file named id_rsa.pub or id_ed25519.pub. If not, generate a new key pair:
Follow the prompts and press Enter to accept the default file location.
You can easily upload your key using the ssh-copy-id
command:
Replace user with your VPS username (e.g., root or ubuntu), and your_vps_ip with your actual VPS IP address. You’ll be prompted to enter your VPS password one last time. If you don’t have ssh-copy-id, you can manually upload the key:
Once the key is uploaded, try logging in:
You should connect without entering a password.
To increase security, you can disable password logins completely (after making sure your key-based access works):
Connect to your VPS.
Edit the SSH config file:
Find and change or add:
Restart the SSH service:
Be cautious — if your key isn’t working properly, you may lock yourself out.
Uploading your SSH public key to a VPS simplifies access and enhances security. Whether you’re managing a single server or dozens, key-based authentication saves time and minimizes risks. Just don’t forget to keep your private key safe and disable password login only after ensuring everything works smoothly.