How to Migrate cPanel Accounts Between Servers Using WHM Transfer Tool (Zero-Downtime Guide) Moving live…
How to Set Up SSH Keys on a Linux VPS (Passwordless Login Guide)

Typing or pasting a complex root password every time you connect to your server slows down daily administration and leaves your VPS exposed to automated brute-force bots. Learning how to set up SSH keys lets you log into your Linux server instantly without typing a password while making unauthorized password guessing impossible.
SSH key authentication replaces traditional passwords with a cryptographic key pair—a private key stored safely on your local computer and a public key placed on your virtual private server. Even if an attacker discovers your server IP address and username, they cannot authenticate without possessing your matching private key file.
This step-by-step guide shows you how to set up SSH keys on a Linux VPS from Windows, macOS, or Linux. You will learn how to generate a modern Ed25519 key pair, copy your public key to the server, test passwordless login safely, and disable password authentication without locking yourself out.

How SSH Key Authentication Works (And Why Ed25519 Is Best)
Before walking through the commands on how to set up SSH keys, it helps to understand the two files created during key generation:
- Private Key (
id_ed25519): Stays strictly on your local laptop or desktop. Never upload, email, or share this file with anyone, including your hosting provider. - Public Key (
id_ed25519.pub): Safe to share and copy onto as many VPS instances as you manage. The server uses this file to verify that your local machine holds the matching private key.
While older tutorials often default to 2048-bit or 4096-bit RSA keys, the official OpenSSH manual pages recommend modern Ed25519 keys. Ed25519 offers stronger cryptographic security, much shorter key strings, and near-instant authentication handshakes across Ubuntu, Debian, AlmaLinux, and Rocky Linux servers.
How to Set Up SSH Keys on a Linux VPS Step-by-Step
Follow these four steps to complete how to set up SSH keys cleanly on your local machine and remote Linux server.
Step 1: Generate an Ed25519 SSH Key Pair on Your Local Computer
Run the key generation command on your own computer—not inside your VPS terminal. Open Terminal on macOS or Linux, or open Windows Terminal / PowerShell on Windows 10 and Windows 11, then run:
ssh-keygen -t ed25519 -C "[email protected]"
The utility walks you through three quick prompts:
- Enter file in which to save the key: Press Enter to accept the default location (
~/.ssh/id_ed25519on macOS/Linux orC:\Users\YourName\.ssh\id_ed25519on Windows). - Enter passphrase (empty for no passphrase): If you want completely passwordless login with zero prompts, press Enter twice to leave the passphrase blank. If you prefer an extra layer of local protection in case your laptop is ever stolen, type a passphrase and press Enter.
- Key fingerprint confirmation: The terminal displays a randomart image and confirms that both your private key and
.pubpublic key have been saved.
Note: If you ever connect to an older legacy server that does not support Ed25519, generate a 4096-bit RSA key pair instead using ssh-keygen -t rsa -b 4096.
Step 2: Copy Your Public Key to Your Linux VPS
Next, transfer the contents of your public key file (id_ed25519.pub) into the ~/.ssh/authorized_keys file on your server. Choose the method below that matches your local operating system.
Option A: macOS and Linux (Using ssh-copy-id)
macOS and Linux include the built-in ssh-copy-id utility—documented in the OpenBSD ssh-copy-id manual—which automatically creates the remote .ssh folder, sets strict file permissions, and appends your public key in one command:
ssh-copy-id -i ~/.ssh/id_ed25519.pub username@YOUR_SERVER_IP
Enter your current VPS password one final time when prompted. Once finished, the terminal prints Number of key(s) added: 1.
Option B: Windows PowerShell (One-Line Command)
Windows does not include ssh-copy-id by default, so use this single PowerShell command to upload your public key and apply the exact permissions Linux requires:
type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh username@YOUR_SERVER_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Type your current server password when prompted, and your public key is installed immediately.
Option C: Manual Copy-Paste (Via Provider Web Console)
If you are using a provider web console or already have an open root terminal session, display your public key locally with cat ~/.ssh/id_ed25519.pub, copy the single line starting with ssh-ed25519, and append it directly on the VPS:
mkdir -p ~/.ssh && chmod 700 ~/.ssh
echo "PASTE_YOUR_PUBLIC_KEY_LINE_HERE" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Step 3: Test Passwordless Login and Create an SSH Shortcut
Before modifying any SSH server settings, verify that your key works properly. Keep your current SSH terminal open as a safety net, open a brand-new terminal window, and connect to your VPS:
ssh username@YOUR_SERVER_IP
If you left the passphrase blank in Step 1, you will land straight inside your VPS shell prompt without entering a password. If you set a passphrase, enter it once—on macOS and Windows, your system SSH agent can cache it automatically for future sessions.
Pro Tip: Save a short host alias in ~/.ssh/config on your local computer so you do not have to remember IP addresses or custom ports:
Host myvps
HostName YOUR_SERVER_IP
User username
IdentityFile ~/.ssh/id_ed25519
With that block saved, connecting to your server takes just two words: ssh myvps.
Step 4: Disable Password Authentication on Your VPS
Leaving password login enabled after learning how to set up SSH keys defeats half the security benefit, because automated bots can still hammer port 22 with password guesses—one of the classic oversights highlighted in our common VPS mistakes guide.
Once you have confirmed in a separate terminal window that your SSH key logs in cleanly, back up your SSH daemon configuration on the VPS:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
As noted in the official Ubuntu OpenSSH Server documentation, Ubuntu 22.04 and Ubuntu 24.04 LTS cloud images frequently place a drop-in override file inside /etc/ssh/sshd_config.d/ (such as 50-cloud-init.conf) that forces PasswordAuthentication yes even if you edit the main config file. Check for drop-in files first:
ls -la /etc/ssh/sshd_config.d/
If a file like 50-cloud-init.conf exists, update PasswordAuthentication no inside that file as well as /etc/ssh/sshd_config. Open the main config file with nano:
sudo nano /etc/ssh/sshd_config
Find and update these three directives (remove any leading # comment symbol if present):
PubkeyAuthentication yes
PasswordAuthentication no
PermitRootLogin prohibit-password
Save and exit nano (Ctrl + X, then Y, then Enter). Always test your SSH configuration syntax before reloading the service so a typo never locks you out:
sudo sshd -t
If sudo sshd -t returns zero output, the syntax is valid. Reload the SSH service to apply your changes:
# On Ubuntu / Debian:
sudo systemctl reload ssh
# On AlmaLinux / Rocky Linux:
sudo systemctl reload sshd
For additional SSH lockdown—such as changing the default port or adding Fail2Ban—follow our complete Linux server hardening checklist.
How to Fix Common SSH Key Errors
If your VPS still asks for a password or rejects your connection after you follow how to set up SSH keys, one of these three issues is almost always the cause:
1. Fixing “Permission denied (publickey)” Errors
OpenSSH strictly refuses to read authorized_keys if your home directory, .ssh folder, or key file has overly permissive write access. Run these exact permission and ownership commands on your VPS (replacing username with your actual Linux username):
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
sudo chown -R username:username ~/.ssh
2. VPS Still Prompts for a Password After Editing sshd_config
As noted in Step 4, Ubuntu cloud templates often include /etc/ssh/sshd_config.d/50-cloud-init.conf or 60-cloudimg-settings.conf. Run grep -rn "PasswordAuthentication" /etc/ssh/ to locate every active override file, change yes to no, validate with sudo sshd -t, and reload SSH.
3. Selecting the Right Key When You Have Multiple SSH Keys
If you maintain separate SSH keys for GitHub, work servers, and personal VPS instances, your SSH client may offer the wrong key first and trigger Too many authentication failures. Add IdentitiesOnly yes under your host block in ~/.ssh/config so SSH only presents the exact key specified for that server.
Frequently Asked Questions About How to Set Up SSH Keys
Should I set a passphrase when learning how to set up SSH keys?
If your top priority is completely frictionless, zero-prompt login from a secure personal desktop, leaving the passphrase empty works fine. However, if you use a laptop while traveling or working in shared spaces, setting a passphrase protects your servers if someone steals your device—and modern SSH agents remember the passphrase for your entire desktop session.
Can I use the same SSH public key on multiple VPS servers?
Yes. Your public key (id_ed25519.pub) is designed to be reused across as many VPS servers, GitHub accounts, and cloud dashboards as you want. Never copy your private key onto another server—only copy the .pub public key.
How do I add a second computer or teammate to my VPS?
Have the second computer or teammate generate their own Ed25519 key pair locally and send you their .pub public key file. Paste their public key onto a new line inside ~/.ssh/authorized_keys on the VPS—each key occupies its own separate line, making it easy to revoke one person’s access later without affecting anyone else.
What happens if I lose my private SSH key after disabling passwords?
If you lose your private key and PasswordAuthentication is set to no, you will not be able to connect over standard SSH. You can still regain access immediately by logging into your VPS provider’s browser-based VNC or Rescue Console, adding a new public key to ~/.ssh/authorized_keys, and rebooting.
Conclusion
Mastering how to set up SSH keys takes less than five minutes and permanently upgrades both your daily workflow and your server security. By generating an Ed25519 key pair, adding your public key to authorized_keys, and disabling password authentication in sshd_config, you eliminate repetitive password prompts and shut down automated brute-force attacks.
Bookmark this guide on how to set up SSH keys for your next server deployment—once your passwordless SSH access is active, check out our step-by-step tutorials on how to install Docker on Ubuntu or how to install CloudPanel to get your applications online fast.
