Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
Cupertino desk4 min

Add Your SSH Public Key to a Server from Linux, macOS, or Windows

Install your SSH public key in the correct account’s accepted-key file, keep the private key on your computer, and check Windows-specific paths and permissions.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To enable SSH key login, create or locate a key pair on your computer, copy the public key to the server account you will use, and save it in that account’s accepted-key file. Keep the private key on your computer. For a typical OpenSSH account, the destination is ~/.ssh/authorized_keys; Windows OpenSSH servers use a different path for administrator accounts.

Know which key goes where

An SSH key pair has a public half and a private half. The public key is usually the file ending in .pub; it is the part you install on the server. Keep the matching private key on your client and do not copy it to the server. The public-key file’s contents are added to authorized_keys on each account where that key should permit login. See the OpenSSH ssh-keygen manual.

As an Amazon Associate I earn from qualifying purchases.

This is your user-authentication key, not the server’s host key. Host keys identify the server to clients; your public key lets the server authorize your account.

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

Generate a key or find one you already have

On Linux, macOS, or Windows with OpenSSH installed, run ssh-keygen and follow the prompts to select a save path and passphrase. If you already have a key pair, locate its matching public-key file rather than generating another unnecessarily. Keep the private key protected on the client; a passphrase can add protection if the private-key file is exposed.

#1 Best Overall
Yubico - Security Key C NFC - Basic Compatibility - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key C NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key C NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key C NFC via USB-C and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Key algorithms and accepted policies depend on the installed OpenSSH version and the server’s configuration, so follow your organization’s requirements rather than assuming one algorithm works everywhere. Microsoft’s Windows guidance documents ssh-keygen and lists DSA, RSA, ECDSA, and Ed25519 support; it identifies Ed25519 as the default when no algorithm is specified. See Microsoft’s OpenSSH key management guide.

Install the key on a standard OpenSSH account

For a typical OpenSSH account, add the complete public-key line to ~/.ssh/authorized_keys in the target user’s home directory. The file is plain text with one key per line. Preserve the full line; its key type and encoded key are essential, while any trailing comment is just an identifier.

Rank #2
Yubico - YubiKey 5C NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-C or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5C NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5C NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5C NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts
  1. Connect to the server using a password or another authorized method, or have an administrator do this for you.
  2. Create the directory if needed: mkdir -p ~/.ssh.
  3. Append the public key: use a trusted transfer method such as scp or paste the public-key line into ~/.ssh/authorized_keys in an authorized server session. Append it rather than overwriting existing keys.
  4. Restrict access: OpenSSH recommends that the .ssh directory and authorized_keys file not be accessible by other users. On a Unix-like OpenSSH server, a common setup is chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. The server’s policy and configuration are authoritative.

If your client has ssh-copy-id, it can copy a public key to an OpenSSH account when you have an initial login method. It is a convenience, not a requirement. The server may use another location through its AuthorizedKeysFile setting, or the account’s home directory may differ from the usual layout. Check the server configuration or ask its administrator if the default path does not work. OpenSSH documents the file format and permission checks in its sshd manual.

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

Use the right key-file path on a Windows OpenSSH server

First ensure that OpenSSH Server is installed, the sshd service is running, and the inbound firewall rule permits SSH connections. Windows installation state and setup steps depend on the Windows release; Microsoft documents these in its OpenSSH installation and first-use guide.

Rank #3
Yubico - YubiKey 5 NFC - Multi-Factor authentication (MFA) Security Key and passkey, Connect via USB-A or NFC, FIDO Certified - Protect Your Online Accounts
  • POWERFUL SECURITY KEY: The YubiKey 5 NFC is the most versatile physical passkey, protecting your digital life from phishing attacks. It ensures only you can access your accounts
  • WORKS WITH 1000+ ACCOUNTS: Compatible with popular accounts like Google, Microsoft, and Apple. A single YubiKey 5 NFC secures 100+ of your favorite accounts, including email, password managers, and more
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 NFC via USB and tap it, or tap it against your phone (NFC), to authenticate. No batteries, no internet connection, and no extra fees required
  • MOST SECURE PASSKEY: Supports FIDO2/WebAuthn, FIDO U2F, Yubico OTP, OATH-TOTP/HOTP, Smart card (PIV), and OpenPGP. That means it’s versatile, working almost anywhere you need it
  • PRIMARY & SPARE KEYS: Just like having a spare house key, we recommend buying two YubiKeys - one for daily use and one as a spare. That way you’ll never get locked out of your accounts

The accepted-key file depends on the Windows account type:

Windows account Public-key file Access rule
Standard user C:Usersusername.sshauthorized_keys Use permissions that prevent other users from accessing the key file.
Member of the local Administrators group C:ProgramDatasshadministrators_authorized_keys Allow only NT AuthoritySYSTEM and BUILTINAdministrators.

For an administrator account, do not put the key only in the user profile’s .sshauthorized_keys; Windows OpenSSH uses the shared administrator key file instead. Microsoft provides the icacls command for setting that file’s required ACLs. Follow the account-specific instructions in Microsoft’s key management guide; Unix chmod permissions do not replace Windows ACLs.

Rank #4
Yubico - Security Key NFC - Basic Compatibility - Multi-Factor Authentication (MFA) Key, Connect via USB-A or NFC, FIDO Certified
  • POWERFUL SECURITY KEY: The Security Key NFC is the essential physical passkey for protecting your digital life from phishing attacks. It ensures only you can access your accounts.
  • WORKS WITH 1000+ ACCOUNTS: Compatible with Google, Microsoft, and Apple. A single Security Key NFC secures 100 of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your Security Key NFC via USB-A and tap it, or tap it against your phone (NFC) to authenticate. No batteries, no internet connection, and no extra fees required.
  • TRUSTED PASSKEY TECHNOLOGY: Uses the latest passkey standards (FIDO2/WebAuthn & FIDO U2F) but does not support One-Time Passwords. For complex needs, check out the YubiKey 5 Series.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Microsoft documents this key-based flow for local and Active Directory accounts, but not Microsoft Entra ID accounts. Windows OpenSSH also does not support AuthorizedKeysCommand or AuthorizedKeysCommandUser; these are Windows-specific limitations, not general OpenSSH rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Test the connection

From the client, connect with the account name and server address:

Best Value
FIDO2 U2F Security Key Passkey Two-Factor Authentication (2FA) USB Key PIN+Touch (Non-Biometric) USB-A Type TrustKey T110
  • Security Key : Protect your online accounts against unauthorized access by using FIDO2 and U2F authentication with T110. It's the world's most protective security key that works with windows, Mac OS, Linux as well as Chrome, Firefox, Edge and many other major browsers.
  • Certified with the new FIDO2 standard, T110 provides the benefit of fast login and strong protection against phishing, account takeover as well as many other online attactks.
  • Works with : Bank of America, Github, Google, Microsoft, DUO, Twitter, Facebook, Dropbox, Apple, ebay, BINANCE, mor and more.
  • Fits USB-A port : Insert the T110 security key into the USB-A port of each service and log in conveniently with one touch
  • For the driver download and user guide, please visit TrustKey Solutions Home support page.
ssh username@server

If the private key is not in a default location or loaded into an agent, specify its path with -i:

ssh -i path/to/private_key username@server

Replace the example username, server, and key path with your actual values. If the connection is rejected, client-side verbose output can help reveal what is happening:

ssh -v username@server

Fix “Permission denied (publickey)”

Check the cause on the server side first, then confirm you are connecting as the intended account:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Wrong username: the key must be installed for the same account named in the SSH command.
  • Wrong key-file path: confirm the account’s actual home directory and the server’s AuthorizedKeysFile setting. On Windows, check whether the target is a standard user or a local administrator.
  • Incomplete public-key line: make sure the full line from the client’s .pub file appears in the accepted-key file as a single line, without wrapping, truncation, or accidental edits.
  • Permissions or ACLs: ensure the server accepts the ownership and access settings on the key file and its containing directory. For a Windows administrator key file, check the specified SYSTEM and Administrators ACLs.
  • Wrong private key offered: if you have several keys, try the matching private key explicitly with -i.

Microsoft’s OpenSSH connection troubleshooting guide lists missing or incorrect authorized_keys files and improper permissions among causes of public-key authentication failures.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.