If you know how to use SSH but have collected old hosts, mystery keys, and years of copied configuration, this cleanup is for you. Shell examples use macOS/Linux unless marked PowerShell. On Windows, your SSH files normally live in %USERPROFILE%\.ssh.
Your laptop can become a route into every server that still accepts your SSH keys. An AI tool with unrestricted access to your account can use the same files and connections you can. Malware can do the same.
Start with three changes: remove access you no longer need, protect your logins with a hardware security key and PIN, and keep AI tools away from your administrator credentials. You do not need a certificate server or a new platform to do this.
Cleaning up SSH reduces the damage a compromised laptop can cause. It does not prevent the laptop itself from being compromised.
A private key stored on your laptop can be copied. If it has no passphrase, that copy can be enough to log in wherever its public key is still accepted.
Even an encrypted key can be usable through an SSH agent, the background service that signs login requests after you unlock a key. Software running as you can often ask that service to authenticate without copying the key. An already-open SSH connection is another route into a server. 1
This applies to Claude Code, Codex, Kimi Code, other agentic tools, and malware. A model does not need malicious intent to cause damage: it can run a harmful command, follow instructions hidden in a repository, or use access you forgot it had.
Do not run an agent with unrestricted approvals in your normal administrator account. Claude Code's --dangerously-skip-permissions, for example, skips permission prompts. A capable agent given a vague goal can try alternative commands or tools to finish the task. Telling it "do not use SSH" is insufficient if it still has a shell and your credentials. 2
Hardware-backed authentication and restricted execution environments put controls outside the model's instructions. Use both.
If the task is editing a project, the tool does not need production SSH, your browser session, or your password manager.
Run the whole tool in a separate, non-administrator OS account or a virtual machine containing only the project files. Do not share your personal or project SSH keys or SSH agent with it. Do not give that account permission to administer the host or switch into your normal local account. A separate folder or terminal tab does not provide this separation.
Limit the tools available too. Prefer a file-editing tool over an unrestricted shell when that is enough. Remove unused plugins and integrations. Keep approvals enabled for commands and new access, and check whether the tool's sandbox covers the whole application or only some commands. 7
If the AI genuinely needs remote access, give it its own key and a separate remote account with only the required permissions. Not your administrator identity. No broad sudo. No ability to change its own access rules. For a repeated operation, a restricted backup or deployment job is safer than a general shell. Remove temporary access afterward.
Check network access as well: a separate user does not isolate a service that grants access to the whole device. For example, Tailscale SSH documents this local-user limitation. 8
For sensitive production administration, use a separate trusted device that does not run unrestricted AI tools. Malware controlling a laptop can undermine the local accounts and virtual machines on it.
Give an isolated AI helper a copy of the configuration it needs, with sensitive details redacted. Keep private keys out of its workspace. Use this brief for the cleanup that follows:
Help me tidy my SSH setup. Start with a read-only review.
List active hosts, duplicates, stale entries, and key references that need
my confirmation. Explain security concerns in plain English.
Do not read private keys, connect to servers, execute commands from the
config, delete files, or change anything yet. Never ask for a passphrase.
Propose small changes that preserve working access. Flag disabled server
identity checks, agent forwarding, and reusable connections. Give me a
backup and test plan. Wait for approval before editing.
This sets the task; the restricted environment enforces the boundary. Do not give the AI helper broad access merely because the prompt tells it to behave.
Make a private backup of ~/.ssh/config before editing it. Use your editor or normal backup tool; keep the copy out of public repositories. If your employer manages the file, ask before changing it.
Look at the files in your SSH directory:
ls -la ~/.ssh
Open ~/.ssh/config. If you have only used PuTTY, use your saved sessions as the inventory; Windows OpenSSH does not read those settings. Make a short list of:
- Hosts you still use and have permission to access.
- Old projects, jobs, and servers you can retire.
- Keys you cannot identify yet.
For each active host, record its owner, login account, and key filename. Give keys useful descriptions in your notes instead of relying on names such as old_key_2. A purpose-first filename with a trailing date, such as id_ed25519_github_deploy_2026-10-17, shows what a key is for and how old it is in a single directory listing. A .pub file contains the public key; keep the corresponding private file out of chats, tickets, and repositories.
If an administrator needs to identify a key, send its public-key fingerprint. For example, using the path of an actual .pub file:
ssh-keygen -lf ~/.ssh/id_ed25519.pub
Do not delete mystery keys until you know whether something still depends on them. Do not test them against former employers' servers to see what works. Ask the owner to identify and remove old access.
Keep one clear entry for each server you still use. Merge duplicates carefully and preserve any required port or jump-host settings. A basic entry looks like this:
Host home-server
HostName server.example.net
User timmy
IdentityFile ~/.ssh/id_ed25519
IdentitiesOnly yes
ForwardAgent no
Use your real hostname, account, and existing key path. IdentitiesOnly yes helps the client offer the intended key. ForwardAgent no avoids giving the remote machine access to your local signing agent. These settings do not stop a local attacker from using your credentials. 3
Ask your AI clanker to flag anything that disables server-identity warnings or keeps connections open for reuse. Have it explain unfamiliar lines before changing them; you do not need to learn every SSH option to remove old entries.
Make one small change at a time, then test with your usual ssh home-server command. Keep a working administrator session or provider console available in case you need to restore the backup. Never dismiss a changed-server-key warning just to make the connection work: verify the change with the server's owner.
Removing a host from this file does not revoke its key. Record which server authorizations need removing. First set up and test replacement access for the hosts you still use.
A Yubico YubiKey, or another FIDO2 security key supported by your SSH setup, is the recommended upgrade for your administrator logins. Copying laptop files alone cannot produce a working copy of its signing key. You will generate a new identity: plugging in a YubiKey does not protect an existing software key. 4
Require physical presence, usually a touch, and user verification, normally a PIN. An authenticator-app code does not protect an SSH key unless the server requires that additional factor.
- SSH software: FIDO-backed SSH keys arrived in OpenSSH8.2 . Requiring PIN verification arrived in8.4 , on both the client and server. Use current, supported packages; these numbers are historical minimums. The client must also include FIDO support.10
- Security key: a YubiKey 5C supports this setup. The
ed25519-skkey type needs YubiKey firmware5.2.3 or newer . Older FIDO2 YubiKeys can useecdsa-skinstead.4 - PIN: set a FIDO2 PIN using Yubico's management software. This is separate from your computer password and any passphrase protecting a local SSH file. You will enter it during key generation and at every login after that.
The YubiKey connects to your computer. The remote server needs compatible SSH software and your public key, not a USB token or Yubico software.
Follow the route for your computer, then continue with key generation.
Yubico documents that Apple's bundled OpenSSH lacks the required built-in FIDO support. If you do not have Homebrew, follow its official installation instructions first. Then install its OpenSSH and select it in your terminal:
brew install openssh
export PATH="$(brew --prefix openssh)/bin:$PATH"
command -v ssh ssh-keygen
ssh -V
Add the PATH line to your shell startup file, usually ~/.zshrc, to keep using this client in new terminals. Check that an IDE or other application making SSH connections uses the intended client too. 4
Current distribution packages normally include FIDO support. On Debian or Ubuntu:
sudo apt update
sudo apt install openssh-client
ssh -V
On another distribution, use its package manager. Have the server owner check the server version as well; updating your laptop does not update the remote host. 4
Microsoft's Win32-OpenSSH added FIDO support in 8.9.0.0. Use a current supported build. Check which programs PowerShell finds:
Get-Command ssh, ssh-keygen
ssh -V
If OpenSSH is missing, too old, or lacks support, use the current official Win32-OpenSSH distribution. Windows' built-in client and Git for Windows can supply different executables, so check the paths rather than assuming the newest installation is being used. 11
If you are moving from PuTTY, create %USERPROFILE%\.ssh in File Explorer if it does not exist. Use your saved connection details and the example in section 3 to create a file named config there, without a .txt extension. Keep your working PuTTY session available while testing the replacement. If OpenSSH asks you to trust the server for the first time, verify its fingerprint with the server owner before accepting it.
If you use PuTTY: standard PuTTY currently lacks native support for these FIDO SSH key types. Use Windows OpenSSH for this procedure. Converting a key to .ppk does not add FIDO support; YubiKey smartcard/PIV setups are a different integration. 12
Do this from your trusted computing environment, outside the AI workspace. Keep existing access and a provider-console recovery route available until the replacement works.
Generate a new identity with a useful name. This single-line command works in a macOS/Linux shell or Windows PowerShell and requests PIN verification:
ssh-keygen -t ed25519-sk -O verify-required -f "$HOME/.ssh/id_ed25519_sk_admin" -C "VPS-Ubuntu-admin"
Do not overwrite an existing key. Insert the YubiKey before running the command; ssh-keygen talks to the device immediately, and enrollment fails without it. Enter the FIDO2 PIN at theEnter PIN for authenticator: prompt, then touch the sensor while its LED blinks to authorize key creation. No passphrase prompt appears: with a hardware key, the file it writes is a key handle, not a usable secret. If generation fails, check the client and vendor setup instructions rather than removing the PIN requirement. Useecdsa-sk instead ofed25519-sk if required by your authenticator.
2.
Install the new public key, the file ending in.pub , on the server. For a directauthorized_keys entry, prefix its public-key line withverify-required so the server enforces user verification too. Ask the server administrator for help if needed.5
3.
Change that host's IdentityFile to~/.ssh/id_ed25519_sk_admin . Test withssh -o ControlPath=none home-server , using your actual alias. This prevents reuse of an existing connection. For this test, have your AI helper restrict theclient to the new key, with no fallback to other keys or passwords. Keep existing server access and recovery available. Confirm that login requires touch and PIN: you enter the FIDO2 PIN, then touch the device while its LED blinks. These gestures gate every login, not just the first. Disconnect, remove the device, and repeat: this test must fail. If it still logs in, correct the test before proceeding.
4.
Enroll a spare security key as a separate identity. Swap in the spare, run the same command with a different filename, and enter the FIDO2 PIN and touch for this key too. Install its public key and test it. Keep the spare safe and make sure provider-console recovery still works.
A touch approves authentication, not the commands that follow. Never approve an unexpected request. An agent or attacker with access to an authenticated session can still run commands. Touch and PIN do not turn an unrestricted agent into a safe administrator.
If hardware is unavailable, keep software keys encrypted with a strong passphrase; generating with a slower KDF (add -a 100 to your ssh-keygen command) raises the cost of brute-forcing a stolen file. A password-manager SSH agent with explicit approval is another option; check how long approval lasts and which applications it covers. Continue with AI isolation and old-key cleanup even if hardware migration must wait. 6
Now that replacement access and recovery work, remove the old software key's authorization from each active server where it is no longer needed. Leaving it accepted creates a route around the hardware requirement. Keep any automation that still needs SSH under its own restricted identity.
For servers you no longer need, ask the owner to remove your public keys and disable any unneeded account. For servers you manage, remove obsolete entries from the relevant accounts' authorized_keys files or the access system that manages them.
Once a key is no longer needed, delete its local files. Keep any required backup encrypted and outside the AI environment. Deleting a laptop file does not revoke a stolen copy, and changing its passphrase does not protect a copy stolen earlier. The server must stop accepting that key.
| Action | Benefit | Cost or limitation |
|---|---|---|
| Retire old keys and host entries | Fewer forgotten routes into servers | Time to identify owners and dependencies; deleting config alone revokes nothing. |
| Hardware key with touch and PIN | Prevents independent reuse of copied laptop key files | Buy a compatible key and spare; allow for login prompts. Open sessions remain usable. |
| Restricted AI environment and remote account | Limits what a mistake or compromise can reach | Setup and upkeep; the host itself must remain trustworthy. |
If you are familiar with AWS SSO, short-lived SSH certificates offer a similar temporary-access model through an existing access service. A certificate is a public permit that works with its matching private key. Expiry prevents new logins; it does not close existing sessions. Use your organization's approved service if one exists, but you do not need to build a certificate authority for this cleanup. 9
OpenSSH 10.6 supports hybrid post-quantum signatures using mldsa44-ed25519, designed to resist known quantum attacks. Both client and server must support and accept the algorithm. 13
These protections address different attacks:
| Threat | Control | Limitations |
|---|---|---|
| Malware or an AI tool copies your SSH private key | FIDO2 security key with touch and PIN | Malware may still use an open connection. Protecting recorded traffic against future decryption also requires post-quantum key exchange. |
| Someone records your SSH traffic to decrypt with a future quantum computer: harvest now, decrypt later | Post-quantum key exchange | Does not stop a future quantum computer from impersonating you or your server. |
| A future quantum computer allows an attacker to impersonate you or your server | Post-quantum keys for your login and the server's identity | Malware can still steal or use a software private key. |
The mldsa44-ed25519 user key is software-stored and does not upgrade your FIDO2 security key. Adding both public keys to authorized_keys lets either one log in, so the software key can bypass FIDO2 security key with touch and PIN.
For this cleanup, keep your FIDO2 security key with touch and PIN. Post-quantum key exchange can work alongside it. 14 Treat post-quantum login and server keys as a separate migration.
Before finishing, confirm that:
- Each retained server has a config entry with the correct account and key, and normal SSH access still works.
- Where you migrated to hardware, the new identity requires touch and PIN; old software keys no longer bypass it where hardware-only access is intended.
- A spare key or provider console provides tested recovery access.
- The AI environment cannot read your keys or use your signing agent, browser session, or administrator network access.
Keep your host-and-key notes current when a project ends or a server is retired. That prevents the next collection of mystery keys.
Use a clean device. Disable the affected access, terminate active sessions, and have reachable servers checked for added keys, changed accounts, or installed persistence. Replace exposed credentials and rebuild compromised machines when their integrity cannot be established.
Keep the laptop, SSH software, AI tools, and plugins patched. Keep recovery access and backups beyond the AI account's control. If you suspect active compromise, investigate it before trusting that laptop with new credentials.
Primary documentation for the controls described here: