Back to blog

ssh-copy-id for a whole fleet: generate and install SSH keys on many hosts

November 17, 2026 7 min read Kubexer Team
SSHSSH Keysssh-copy-idSecurity

Moving off passwords sounds like a small job until you count the servers. One host: generate a key, run ssh-copy-id, done. Twenty hosts, several of them behind a bastion, with different usernames: it is an afternoon, and the interesting risk is not the typing — it is locking yourself out halfway through.

How people do it today

The classic recipe has three steps:

ssh-keygen -t ed25519 -C "deploy@laptop"
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@web-01.example.com
ssh -i ~/.ssh/id_ed25519 deploy@web-01.example.com

What ssh-copy-id does is modest: it appends your public key to ~/.ssh/authorized_keys of the user you logged in as, creating the directory and file with strict permissions if needed. For a fleet, people wrap it in a shell loop over a host list. That works, with three recurring problems:

  • The private key sits in ~/.ssh on a laptop and, sooner or later, gets copied to a second machine so "it works from there too".
  • Nothing proves the key works until you try it by hand — and the moment you also switch off password login on the server, a key that does not work is a locked door.
  • Failures are quiet. One host with an unusual shell, a read-only home directory or an unaccepted host key breaks in the middle of a loop, and you find out later.

The safe order of operations

Whatever tool you use, the sequence that avoids lockouts is always the same: install the key, prove it logs in on its own, and only then change how you connect. Never the other way around. The proof matters because an SSH agent or a saved password can make a connection succeed even when the new key is not what authenticated it.

How Kubexer Terminal does it

Key deployment lives in a connection vault, next to your hosts and identities.

1. Generate

Open a vault, go to Identities, choose Generate SSH key, and give it a name and the username it logs in as. You pick Ed25519 (the recommendation) or RSA 4096, and optionally a passphrase. The key is generated inside the app's main process and saved straight into the vault as an identity. The private key never leaves the vault unless you explicitly export it; the interface only ever receives the public half. Export, when you want it, writes the private key with owner-only permissions next to its .pub file.

Generating a key is free.

2. Pick the hosts

Choose Install on hosts… from the key's menu. You can tick individual hosts and whole groups; only SSH hosts are listed, so RDP and VNC entries stay out of it. Group membership is resolved when you start, so the run covers the hosts in the group at that moment.

3. Install, idempotently

For each host Kubexer connects with the host's current login, then runs a small script as that user. The script makes sure ~/.ssh exists with mode 700 and authorized_keys with mode 600, and adds the key only if it is not there already. "Already there" is judged on the key type and key data, not the free-text comment, so a copy of the same key added earlier under a different comment is recognised and not duplicated. It also handles a file that does not end in a newline, so the new key is never glued onto the previous line. Running the install twice is harmless — the second run reports already installed.

Two refusals are deliberate. If authorized_keys is a symlink, Kubexer leaves it alone and says so rather than writing through it. And before running anything, it checks the host is a Unix-like system; a Windows OpenSSH server is skipped with a clear message, because that file lives somewhere else and works differently there. Windows OpenSSH hosts are not supported yet.

Hosts are processed several at a time, each on its own connection, and one failing host never stops the others. Host keys are checked strictly: a host whose fingerprint you have not trusted yet fails with Connect to this host once to trust its host key instead of being silently accepted. Connect once, accept the fingerprint, retry. That is the same trust-on-first-use model Kubexer Terminal uses for every SSH connection.

4. Verify with a key-only login

After adding the key, Kubexer opens a second connection to the same host using only the new key — no password, no agent. If that login works, the host is marked verified. If it does not — for example because the server does not allow key logins at all — the key is still installed, the host is reported as not verified with the server's reason, and nothing about the host's configuration changes.

5. Switch hosts, only after verification

There is an optional checkbox: Switch these hosts to log in with this key after it is verified. A host is switched only if the verify succeeded and the host's username matches the key's. When it is switched, the host points at the new identity and its old inline credentials are dropped, so a stale password does not shadow the key. If the usernames differ, the host is left alone and the result says why. That is the lockout protection: your saved login only changes once the replacement is proven.

Taking a key back out

The same drawer has a Remove mode that deletes the key's line from authorized_keys on the chosen hosts, replacing the file atomically and keeping its permissions. It refuses one thing on purpose: a host that currently logs in with that key is skipped, so removal cannot cut off the very connection doing the work. Move that host to another login first.

What this does not do

  • It does not touch the server's SSH configuration. If PubkeyAuthentication is off, the verify step will tell you; it will not turn it on.
  • It installs into the login user's own authorized_keys. It is not a way to give another person access under their own account — Kubexer's access profiles are for that.
  • It does not disable password login for you. Do that on the server, after you have seen every host verified.
  • It needs a working login to start with — it copies a key using a connection that already works.

Free versus Pro

Generating a key pair is free. Installing a key on hosts, and removing it, is a Pro feature, as is the optional switch-over. Kubexer Terminal is available for macOS, Windows, and Linux.