Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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 PC×
Skip to content
World desk5 min

How to Set Up SSH Keys and Disable Password Login

Set up SSH key login safely: generate a client key, install the public key for the right account, verify a fresh connection, then disable password authentication.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Generate a key pair on your client, add its public key to the correct server account, and verify that key-based login works before disabling password authentication. Keep your current SSH session open until a new connection succeeds; otherwise, a configuration mistake or missing key could lock you out.

What changes when you switch to SSH keys?

SSH key login uses a public/private key pair. The private key stays on the computer you connect from; the server stores the matching public key in the account’s authorized keys file. When you connect, the key pair lets the server authenticate you without accepting an account password.

As an Amazon Associate I earn from qualifying purchases.

Disabling password authentication changes what the SSH server will accept. It does not install a key for you, and it does not necessarily disable every interactive authentication method. The steps below use Ubuntu Server paths and commands; other distributions and managed hosts may use different configuration and service procedures.

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

1. Generate a key pair on your client

On the computer you will connect from, run:

ssh-keygen -t ed25519

Choose a strong passphrase when prompted. Ubuntu recommends Ed25519 for its ordinary setup and documents RSA 4096-bit as an alternative if Ed25519 is unavailable in a constrained environment. Client defaults can vary; Ubuntu’s documented default files are ~/.ssh/id_ed25519 for the private key and ~/.ssh/id_ed25519.pub for the public key. See Ubuntu’s OpenSSH server guide.

#1 Best Overall
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
  • Keep the private key file private and on the client. Do not copy it to the server.
  • Only the public key—the file ending in .pub—belongs in the server account’s authorized keys.
  • A passphrase helps protect the private key if someone gains access to its file. Ubuntu notes that ssh-agent can reduce repeated passphrase prompts.

2. Install the public key for the intended account

While you can still use the server’s existing login method, Ubuntu documents ssh-copy-id as the convenient way to install the key:

ssh-copy-id username@target_machine

Replace username with the account you intend to use and target_machine with the server’s hostname or address. The command appends the public key to that remote account’s ~/.ssh/authorized_keys file. OpenSSH’s documented default authorized-key paths include .ssh/authorized_keys and .ssh/authorized_keys2, though server configuration can change the paths; see the OpenBSD sshd_config(5) reference.

Rank #2
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.

If ssh-copy-id is unavailable, append the contents of your public key file to the correct account’s authorized keys file using a trusted method. Check the account and host carefully: a valid key installed for a different user will not authorize the login you intend.

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

3. Test key login before changing server settings

Open a second terminal and connect as the intended account. If your client does not select the new key automatically, specify it explicitly:

ssh -i ~/.ssh/id_ed25519 username@target_machine

Confirm you can establish a new session using the key while leaving your existing administrative session open. Do not proceed until this test succeeds. Ubuntu warns that disabling password access without a usable approved key can leave you unable to log in; see its SSH configuration guidance.

4. Disable password authentication on Ubuntu

In the server’s existing session, inspect /etc/ssh/sshd_config and the included configuration snippets under /etc/ssh/sshd_config.d/. Ubuntu’s main configuration includes files matching that directory’s pattern, so a local or provider-supplied snippet may affect the effective setting.

Set this directive in the effective server configuration:

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

Keep public-key authentication enabled. OpenSSH documents PubkeyAuthentication as enabled by default in the cited reference, but check the effective configuration rather than relying on a default. The OpenSSH reference defines PasswordAuthentication as the setting that specifies whether password authentication is allowed.

Best Value
Yubico - YubiKey 5Ci - Multi-Factor authentication (MFA) Security Key and passkey for iPhone/Android/PC, Dual connectors for Lighting/USB-C, FIDO Certified
  • POWERFUL SECURITY KEY: The YubiKey 5 is a versatile physical passkey that protects 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 secures 100+ of your favorite accounts, including email, password managers, and more.
  • FAST & CONVENIENT LOGIN: Plug in your YubiKey 5 via USB and tap it 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.
  • BUILT TO LAST: Made from tough, waterproof, and crush-resistant materials. Manufactured in Sweden and programmed in the USA with the highest security standards.

Check keyboard-interactive authentication separately

PasswordAuthentication and KbdInteractiveAuthentication control separate OpenSSH authentication methods. Turning off password authentication alone does not necessarily turn off every password-like or interactive prompt. Keyboard-interactive authentication may be part of a PAM, multi-factor, or other challenge-response setup.

Set KbdInteractiveAuthentication no only if your policy also forbids that method and you have confirmed that no required authentication flow depends on it. OpenSSH describes keyboard-interactive separately, and Ubuntu’s manual lists both password and keyboard-interactive among available authentication methods. Review the OpenSSH configuration reference and Ubuntu’s sshd_config manual for the relevant settings.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. Validate, apply, and verify the change

Use the configuration-validation and service reload or restart procedure documented for your operating system and deployment. There is no single apply command established here for every distribution, cloud image, or managed host, so do not assume an Ubuntu procedure applies elsewhere.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Validate the server configuration using the procedure for your platform.
  2. Apply the change using that platform’s documented service procedure, keeping your existing session open.
  3. Open a new connection and confirm that it authenticates with the intended key.
  4. Only after the new connection works should you close the original session.

If the new connection fails, use the still-open session or an out-of-band provider console to correct the configuration or restore access. The alternative recovery path matters because a user without an approved key may no longer have an ordinary SSH login route.

Key login versus password login

Question Key-based login Password login
What must be available? The client must have the private key, and the matching public key must be authorized for the server account. The server must permit password authentication, and the user must know the account password.
What happens if the credential is unavailable? Without the approved private key, ordinary key login cannot proceed; another tested access path may be needed. Without the password, password login cannot proceed; another permitted authentication method may be needed.
Can the credential file be protected? A passphrase can protect the private key file; an agent can help avoid entering it for every use. The account password is entered for authentication; this setup does not use a private-key file.

These are operational differences, not measured comparisons of compromise or failure rates. The cited sources do not establish numerical superiority claims.

Before you close your current session

  • A new connection works for the intended username and host.
  • The matching public key is in that account’s authorized keys file.
  • The private key remains on the client and is protected with a passphrase.
  • The effective server configuration disables password authentication without unintentionally breaking a required keyboard-interactive or MFA flow.
  • You have a working recovery route, such as the open session or provider console, until the change is verified.

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
PC Slower Than It Used to Be?Free scan - under a minute

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.