October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Add an SSH Key to Your VPS or VDS: A Safe Setup Guide

Add your SSH public key to the correct VPS account, check ownership and permissions, and verify a fresh login before closing your existing session.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To add an SSH key to a self-managed VPS or VDS, put the client’s public key in the intended server account’s ~/.ssh/authorized_keys, set safe ownership and permissions, then test a new connection before closing your existing session. Keep the matching private key on your own computer; never upload it to the server.

Before you change SSH access

Have the server’s address or hostname, the correct login name, and the configured SSH port ready. Confirm you still have a working SSH session or an out-of-band recovery route, such as the hosting provider’s console. If you are already locked out, use that provider’s documented recovery procedure; console access and firewall controls vary by provider and operating system.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The steps below describe the usual OpenSSH arrangement. The OpenBSD project manuals for ssh-keygen(1), sshd_config(5), and sshd(8) were current in October 2026. A Linux distribution may ship a different OpenSSH release or local configuration, so check the documentation for the software installed on your server.

What the two SSH keys do

A key pair consists of a private identity file and a corresponding public-key file, usually ending in .pub. The client uses the private key to prove its identity; the server checks whether the matching public key is authorized for the account being accessed. The server’s default authorized-key file is ~/.ssh/authorized_keys, but its configuration can specify another location. See the OpenBSD ssh-keygen(1) and sshd_config(5) manuals.

Separately, your client’s known_hosts data records server host keys. This lets the client recognize the server; it is not where you install your client public key. OpenSSH explains this distinction in sshd(8).

Generate or find a key on your computer

Run these commands on the computer from which you will connect, not in the server shell. First inspect ~/.ssh for an existing key pair so you do not accidentally overwrite a private key. If you need a new key, a representative command for a current OpenSSH client is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ssh-keygen -t ed25519 -C "admin@laptop"

Check that your installed client and local security policy support the selected algorithm. When prompted, choose a passphrase to encrypt the private key at rest unless a documented automation requirement calls for a different managed approach. Keep the private identity file—such as id_ed25519—on your computer and readable only by your account. Copy only its matching .pub file to the server. OpenSSH documents key generation, file roles, and passphrases in ssh-keygen(1).

Install the public key for the intended server account

Install the key under the account that should log in. For example, a key placed in /root/.ssh/authorized_keys does not automatically authorize the deploy account. The usual default is an authorized_keys file in that user’s home directory; administrators should check AuthorizedKeysFile in the server’s SSH configuration if the default does not apply. See sshd_config(5).

Use ssh-copy-id when available

If you can already connect to the destination account with a supported method, ssh-copy-id can install the public key where the server expects it. For example:

ssh-copy-id -i ~/.ssh/id_ed25519.pub [email protected]

Include the appropriate port if the server does not use the client’s default SSH port. Verify the target username and host before running the command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
HP MicroServer Gen10 Plus Mini Tower Server, Intel Xeon E-2224 3.4GHz, 32GB RAM, 16TB Storage, RAID, Windows Server 2019
  • HP MicroServer Gen10 Plus Tower Server for Business with Microsoft Windows Server 2019 OS!
  • Intel Xeon E-2224 Quad-Core 3.4GHz 8MB CPU, Up To 4.6GHz Turbo
  • 32GB (2 x 16GB) DDR4 PC4-21300 2666MHz Unbuffered Memory
  • 16TB (4 x 4TB) 7.2K 6Gb/s SATA 3.5" HDDs in RAID
  • Hard drives and memory upgrades included separately NOT installed, installation required.

Append the public key manually

If using ssh-copy-id is not an option, use your existing session or the provider console to create the destination account’s SSH directory and append the complete, single-line contents of the local .pub file to its authorized_keys. On a Unix-like server, the common permission pattern is:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
cat >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

After running the commands, paste the public-key line into the waiting cat command and finish input with Ctrl-D. Alternatively, transfer the public-key file using a supported method, then append its contents. Confirm that the directory and file belong to the destination account, not to a different user. These are common Unix conventions; check the target system’s documentation for its requirements. OpenSSH’s StrictModes checks ownership and permissions for the user’s home and SSH files and is enabled by default in the documented configuration. See sshd_config(5) and sshd(8).

Test a fresh login before closing the old session

Open a second terminal on your computer and connect as the intended account, specifying the private identity if needed:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ssh -i ~/.ssh/id_ed25519 [email protected]

If the server uses a nonstandard port, add -p PORT with the port actually configured on that server. Make sure the client offers the intended identity and that the server accepts it. If authentication fails, use verbose client output with ssh -v and check the server’s authentication logs for the relevant operating system. Keep your original working session open until this fresh login succeeds.

On a first connection, the client may ask whether to trust the server’s host key. When practical, verify its fingerprint through a trusted provider console or another independent channel. A changed-host-key warning can indicate that the server was reinstalled or its host key changed, but it can also signal an unexpected host; investigate rather than casually bypassing the warning. OpenSSH describes host-key records and verification in sshd(8).

If the server rejects the key

  • Wrong account or key location: Check the login name, the account’s home directory, and the configured AuthorizedKeysFile. The key must be authorized for the account you are logging into. See sshd_config(5).
  • Unsafe ownership or permissions: Check the home directory, .ssh, and authorized_keys. With StrictModes enabled, OpenSSH rejects unsafe ownership or modes. See sshd_config(5).
  • The client offered a different key: Use -i to select the intended private identity. Do not put the private key on the server. See ssh-keygen(1).
  • Server settings or service state: Check whether public-key authentication is permitted, whether AuthorizedKeysFile was changed, and whether the SSH service is listening on the expected port. The documented OpenBSD configuration defaults PubkeyAuthentication to yes, but distributions and local settings can differ. See sshd_config(5).
  • Network or firewall path: Check the provider-level firewall and the guest operating system’s firewall, along with the actual SSH port. Their controls and commands depend on your provider and operating system.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Optional: use a hardware-backed key

OpenSSH also supports FIDO security-key types on compatible clients and servers. This is an advanced alternative, not a requirement for ordinary SSH access. A passphrase encrypts a software-held private key; a FIDO authenticator can tie key operations to a physical device, and server configuration can require user presence or verification. Before choosing this route, confirm support across the client and server and plan how you will recover access if the authenticator is unavailable. See ssh-keygen(1) and sshd_config(5).

Replacing a lost or exposed key

If a private key may have been exposed, remove its public-key line from every applicable authorized-keys file and install a replacement through a trusted working session or recovery route. A public key alone does not disclose its private half, but removing an old authorization is prudent if the associated private key is compromised. Managed deployments can also use OpenSSH’s revoked-key configuration; see sshd_config(5).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not disable password authentication or change root-login policy as part of the key installation unless you have separately chosen and verified that policy. First confirm a fresh key-based login and a recovery path; the appropriate authentication policy depends on how the server is administered.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.