Skip to content
betterstack-alchemyUnofficial

Cloud.Ssh

Kind BindingType id BetterStack.Cloud.SshSource src/Cloud/Ssh.tsLive test available A live lifecycle test exists: it runs against the offline mock by default and against the real API under bun run test:live. This records that the test exists, not a dated live run (see Compatibility). Test file: test/Cloud/Ssh.local.test.ts.

SSH exec/scp against a Cloud.Server. Uses the server’s Alchemy-managed deploy key (installed when the server was created) and root, unless privateKey / user are passed.

Every connection checks the server’s host key against a known_hosts written for that session only, never ~/.ssh/known_hosts and never StrictHostKeyChecking=no:

  • pinned — the server’s hostPublicKey (Alchemy generated the pair and installed it at first boot, or recorded it at the first login): StrictHostKeyChecking=yes; any other key is refused with SshError reason: "host-key-mismatch" before a command or a file is sent;
  • none known (bootstrap: false, looked-up servers, servers created before pinning) — trust on first use for that session (accept-new), logged as a warning; pass hostKey to pin one.

Connections drop after a minute without an answer (ServerAliveInterval).

Exec a command

const ssh = yield* BetterStack.Cloud.Ssh(server);
const { stdout } = yield* ssh.exec("uname -a");

Copy a file

const ssh = yield* BetterStack.Cloud.Ssh(server);
yield* ssh.scp("/tmp/app.zip", "/opt/app/bundle.zip");