NEWUse coupon code SMX20 to get 20% OFF your first billing cycle on any game server or VPS!Explore Store

VPS HOSTING

How to Set Up SSH Key Authentication for a VPS on Windows, macOS and Linux

Generate an Ed25519 SSH key on Windows, macOS or Linux, copy it to your VPS, disable password logins safely, use an SSH config file and agent, and fix permission errors.

Password logins are the weakest point of most servers. Every public VPS sees constant automated attempts to guess SSH passwords. SSH keys remove that risk: authentication uses a cryptographic key pair, the secret half never leaves your computer, and there is no password to guess. Once keys work, you can turn password authentication off completely.

This guide covers all three desktop platforms, the safe order of steps so you never lock yourself out, and the permission problems that make key logins silently fail.

How SSH Keys Work

  • The private key (for example ~/.ssh/id_ed25519) stays on your computer. Anyone holding it can log in as you, so protect it with a passphrase.
  • The public key (id_ed25519.pub) is safe to share. You place it in ~/.ssh/authorized_keys on each server.
  • When you connect, the server challenges your client to prove it holds the matching private key. No secret is sent over the network.

Ed25519 is the recommended key type today: short keys, fast, and strong. Use RSA (with at least 3072 bits) only for very old systems that do not support Ed25519.

Step 1a: Generate a Key on macOS or Linux

ssh-keygen -t ed25519 -C "you@laptop-2026"

Accept the default location (~/.ssh/id_ed25519) and enter a passphrase. The -C comment just labels the key so you can recognise it later in authorized_keys.

Step 1b: Generate a Key on Windows 10 or 11

Windows includes the OpenSSH client. Open PowerShell and run the same command:

ssh-keygen -t ed25519 -C "you@windows-pc"

Keys are saved in C:\Users\YourName\.ssh\. If ssh is not recognised, add the "OpenSSH Client" optional feature in Settings. PuTTY users can generate keys with PuTTYgen, but PuTTY's .ppk format must be converted for OpenSSH; using the built-in OpenSSH client avoids that step.

Step 2: Copy the Public Key to the VPS

On macOS and Linux, ssh-copy-id appends the key and sets correct permissions:

ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@203.0.113.10

Windows does not ship ssh-copy-id. This PowerShell one-liner does the same job:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh admin@203.0.113.10 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Both methods ask for the account password one last time. If the server already has password logins disabled, add the key through your provider's web console instead, by pasting the contents of the .pub file into ~/.ssh/authorized_keys.

Step 3: Test Key Login Before Changing Anything

ssh -i ~/.ssh/id_ed25519 admin@203.0.113.10

You should be asked for the key's passphrase (a local prompt), not the server password. If you are still asked for the server password, the key was not accepted; jump to the troubleshooting section before going further.

Step 4: Use a Non-Root Admin User

Log in as a normal user with sudo rather than as root. If you only have root, create a user and copy your key to it:

adduser admin
usermod -aG sudo admin
mkdir -p /home/admin/.ssh
cp /root/.ssh/authorized_keys /home/admin/.ssh/
chown -R admin:admin /home/admin/.ssh
chmod 700 /home/admin/.ssh && chmod 600 /home/admin/.ssh/authorized_keys

Test ssh admin@server and sudo -v in a new terminal before continuing.

Step 5: Disable Password Logins

Keep your current session open. On Ubuntu and Debian, create a drop-in file so package updates do not overwrite your change:

sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PermitRootLogin no
EOF
sudo sshd -t && sudo systemctl reload ssh

sshd -t checks the configuration for errors before you reload. On some distributions the service is called sshd instead of ssh. Then, from a new terminal, confirm that key login still works and that password login is refused:

ssh admin@203.0.113.10
ssh -o PubkeyAuthentication=no admin@203.0.113.10   # should fail: Permission denied (publickey)

Check for files that might override your setting with sudo sshd -T | grep -i passwordauthentication. OpenSSH uses the first value it reads for each setting, and files in sshd_config.d/ are read in alphabetical order. Some cloud images ship a file such as 50-cloud-init.conf that sets PasswordAuthentication yes, which is why the example file is named 00- so it is read first. If the effective value is still yes, find the conflicting file with sudo grep -ri passwordauthentication /etc/ssh/.

Step 6: Make Logins Convenient

An SSH config file saves typing. Create or edit ~/.ssh/config (on Windows, C:\Users\YourName\.ssh\config):

Host myvps
    HostName 203.0.113.10
    User admin
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

Now ssh myvps is all you need, and tools such as scp, rsync, Git and VS Code Remote-SSH use the same entry.

To avoid typing the passphrase every time, use the SSH agent:

# macOS / Linux
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Windows (PowerShell as Administrator, once)
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
# then, as your normal user
ssh-add $env:USERPROFILE\.ssh\id_ed25519

Managing Several Keys and Devices

  • Create one key per device (laptop, desktop, CI system) rather than copying one private key around. If a device is lost, remove just its line from authorized_keys.
  • Label keys with -C so each line in authorized_keys is identifiable.
  • For CI/CD deploy keys, create a dedicated key without shell privileges where possible, and store it in the CI secret store, never in the repository.
  • Keep a backup of your private key (with its passphrase) in a password manager, or have a second authorised key, so losing one laptop does not lock you out.

ServoMix Plans for This Workload

SSH keys work the same on every plan. Every ServoMix Linux VPS includes full root access, so you can add keys and change the SSH configuration yourself.

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
SMX vCore XS (Intel Xeon)28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹270/moBusiness websites, small apps, scheduled jobs and botsOrder
SMX vCore S (Intel Xeon)416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
SMX vCore M (Intel Xeon)832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
SMX vCore L (Intel Xeon)1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,248/monthHigh-memory workloads and consolidated production serversCheck stock

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
SMX vPro XS (AMD EPYC)28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹420/moWebsites, small APIs, bots, staging and VPN serversOrder
SMX vPro S (AMD EPYC)416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹560/moWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
SMX vPro M (AMD EPYC)832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹840/moProduction databases, high-traffic sites, multi-container appsOrder
SMX vPro L (AMD EPYC)1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹1,120/moLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Prices are monthly in INR as listed on the ServoMix store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Troubleshooting Key Logins

Run the client in verbose mode to see what it offers: ssh -v admin@server. On the server, read the reason in the log: sudo journalctl -u ssh -n 50 (or /var/log/auth.log).

ProblemFix
"Authentication refused: bad ownership or modes"chmod 700 ~/.ssh, chmod 600 ~/.ssh/authorized_keys, and make sure the home directory is not group- or world-writable
Still asked for the server passwordPublic key not in the right user's authorized_keys, or a line break inside the key line
"UNPROTECTED PRIVATE KEY FILE" on WindowsThe private key file is readable by other users; restrict its permissions to your account only
"Too many authentication failures"The agent offers many keys; set IdentitiesOnly yes and IdentityFile in ~/.ssh/config
Locked out after disabling passwordsUse the provider's web console to fix authorized_keys or re-enable passwords temporarily

Frequently Asked Questions

Which SSH key type should I use?
Ed25519. It is secure, fast and supported by every current OpenSSH version. Use RSA 3072 or 4096 bits only for legacy systems that lack Ed25519 support.
Is it safe to share my public key?
Yes. The public key (.pub) is designed to be placed on servers and shared. Never share the private key file.
Should I set a passphrase on my SSH key?
Yes. A passphrase encrypts the private key on disk, so a stolen laptop or backup does not give immediate server access. Use the SSH agent so you only type it once per session.
How do I copy an SSH key from Windows without ssh-copy-id?
Pipe the public key into the server's authorized_keys with PowerShell: type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys", then fix permissions to 700 and 600.
Will disabling password authentication lock me out?
Not if you first confirm key login works in a separate session. Keep your original session open while you test, and know how to reach your provider's web console.
Why does SSH still ask for my server password?
The server did not accept your key. Common causes are wrong permissions on ~/.ssh, the key added to a different user, or the client offering a different key. Run ssh -v and check the server's auth log.
Can I use the same key for several servers?
Yes, one key per device can be authorised on many servers. Avoid copying one private key to many devices, so you can revoke a single device if it is lost.
Should I change the default SSH port?
It reduces log noise from bots but is not real security. Key-only authentication matters far more. If you change the port, update your firewall and SSH config before reloading.
How do I remove access for a lost laptop?
Delete that key's line from ~/.ssh/authorized_keys on every server. Labelling keys with -C makes the right line easy to find.
Can I use SSH keys on a ServoMix VPS?
Yes. Every ServoMix Linux VPS includes full root access, so you can add your public key to authorized_keys and harden the SSH configuration as described above.

Frequently Asked Questions

Which SSH key type should I use?

Ed25519. It is secure, fast and supported by every current OpenSSH version. Use RSA 3072 or 4096 bits only for legacy systems that lack Ed25519 support.

Is it safe to share my public key?

Yes. The public key ( .pub ) is designed to be placed on servers and shared. Never share the private key file.

Should I set a passphrase on my SSH key?

Yes. A passphrase encrypts the private key on disk, so a stolen laptop or backup does not give immediate server access. Use the SSH agent so you only type it once per session.

How do I copy an SSH key from Windows without ssh-copy-id?

Pipe the public key into the server's authorized_keys with PowerShell: type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" , then fix permissions to 700 and 600.

Will disabling password authentication lock me out?

Not if you first confirm key login works in a separate session. Keep your original session open while you test, and know how to reach your provider's web console.

Why does SSH still ask for my server password?

The server did not accept your key. Common causes are wrong permissions on ~/.ssh , the key added to a different user, or the client offering a different key. Run ssh -v and check the server's auth log.

Can I use the same key for several servers?

Yes, one key per device can be authorised on many servers. Avoid copying one private key to many devices, so you can revoke a single device if it is lost.

Should I change the default SSH port?

It reduces log noise from bots but is not real security. Key-only authentication matters far more. If you change the port, update your firewall and SSH config before reloading.

How do I remove access for a lost laptop?

Delete that key's line from ~/.ssh/authorized_keys on every server. Labelling keys with -C makes the right line easy to find.

Can I use SSH keys on a ServoMix VPS?

Yes. Every ServoMix Linux VPS includes full root access, so you can add your public key to authorized_keys and harden the SSH configuration as described above.

Was this article helpful?

Your feedback helps us continuously improve ServoMix guides.

Share this article

Know someone who may find this guide useful?

SSH Key Authentication for a VPS: Windows, macOS, Linux | ServoMix