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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use OpenSSH’s ssh-agent to unlock a passphrase-protected private key once, then let SSH clients use that loaded identity while it remains available to the agent. Start or connect to an agent, add the key with ssh-add, and configure SSH to add a key automatically if that better fits your workflow.

How the SSH agent stops repeated passphrase prompts

An SSH agent holds identities for public-key authentication. It starts with no keys; ssh-add loads a private-key identity into it. You enter the key’s passphrase when adding it, and SSH clients connected to that agent can use the loaded identity without unlocking the key file for each authentication. The identity remains usable only while it is loaded and the agent is available.

SSH clients find the agent through their environment, especially SSH_AUTH_SOCK, which identifies the Unix-domain socket used to communicate with it. If a shell or program does not inherit the right environment, it may not reach the agent you expect. See the OpenBSD ssh-agent manual.

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

Load a key manually for your shell session

  1. Start an agent if your environment has not already provided one. In a shell login, ssh-agent can print commands to evaluate in the calling shell so that it receives the agent environment. Follow the syntax for your shell; do not start another agent if your environment already provides one.

    #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.
  2. Add your private key, substituting its actual path if it is not the default:

    ssh-add ~/.ssh/id_ed25519

    Enter the key’s passphrase when prompted. The agent now has that identity available to connected SSH clients.

  3. Connect as usual, for example with ssh user@host. If the client is connected to the same agent and selects the loaded identity, it can authenticate without asking you to unlock the key again.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    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

Use ssh-add again when you need to load another identity. For the command’s behavior and options, see the OpenBSD ssh-add manual.

Choose between manual and automatic loading

Manual loading with ssh-add

With the manual approach, you decide when the key enters the agent and can load only the identities you need. It requires an explicit ssh-add command for a new agent session or after an identity is no longer loaded.

Automatic loading with AddKeysToAgent

To have SSH add a file-backed key to an agent when the key is loaded, set AddKeysToAgent yes for the relevant host in ~/.ssh/config:

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
Host example
    HostName example.org
    User alice
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes
    AddKeysToAgent yes

With this setting, the key may be added as part of using the matching SSH configuration rather than through a separate manual command. That is more convenient, but makes adding the configured key less deliberate. The current OpenBSD ssh_config manual documents AddKeysToAgent as defaulting to no; check the manual for your installed OpenSSH version because platform packages can differ.

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

Set key lifetime and use limits

An identity can remain available for the life of the agent unless you set a lifetime. In ssh_config, AddKeysToAgent can take a time interval to set a key lifetime; it can also use confirm to require confirmation on each use. For example, a finite interval trades some convenience for limiting how long the identity remains loaded. Choose a value that suits your work and trust in the devices and sessions where the agent is accessible; the manuals do not prescribe one universal duration.

Manual and automatic loading are separate from lifetime: either way, consider whether you want an identity available indefinitely for that agent session or only for a defined interval. Consult the installed version’s ssh_config options for accepted interval syntax and platform-specific behavior.

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.

Control which key a host uses

If the agent holds several identities, narrow what a host can use with IdentityFile and IdentitiesOnly yes. In the example above, those settings identify the intended key rather than offering every identity available through the agent.

You can also control agent selection with IdentityAgent: set it to a particular socket when a host should use a specific agent, or set it to none to disable agent use for that host. These choices are useful when a shell can access more than one agent or when a particular connection should not use one.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Understand agent forwarding before enabling it

Agent forwarding lets a remote host use your local agent for onward authentication; it does not copy the private-key file to that host. That distinction does not make forwarding harmless: someone on the remote host who can access the forwarded socket may request authentication operations using identities loaded in your local agent, even though they cannot obtain the key material itself.

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.

Leave forwarding disabled unless you need it for a specific onward connection, and forward only to a remote machine you trust. Forwarding delegates access to agent operations for the duration and scope of that connection.

Troubleshoot a key that is not being used

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.