lmssh authoring skill

lmssh is a static single-file executable embedding OpenSSH 10.6p1 client tools (ssh, sftp, scp, ssh-keygen) and the lmcode-cpp bytecode VM. It executes direct OpenSSH client commands as well as compiled _lmcode_ automation scripts for parallel fleet execution, atomic file deployment, SSH key and CA lifecycle management, and standard REST and CLI routing.

Purpose

Use lmssh to automate remote shell execution across single hosts or parallel server fleets, upload and download files or directories over SCP and SFTP, verify SHA-256 digests before atomic remote renames, generate Ed25519 or RSA keys, mint SSH CA user or host certificates, sign and verify artifacts with ssh-keygen -Y, maintain known_hosts inventories, and expose SSH operations through standard lmcode_std_v3 REST and CLI interfaces.

When to use it

Choose lmssh whenever a workflow needs deterministic SSH command execution, unattended SFTP/SCP file synchronization, SSH certificate authority issuance, or artifact signature verification without depending on a system OpenSSH installation. Use lmssl when working with X.509 certificates, TLS handshakes, or raw libcrypto primitives, and use lmcurl when testing HTTP, HTTPS, or LDAPv3 endpoints.

Install

Install the lmctl toolchain with npm install -g @lmctl-ai/lmctl@latest. Pre-built static Linux binaries (musl x64 and arm64) and macOS binaries (x64 and arm64) are published on GitHub Releases and resolved automatically when an LMScript program declares cli="lmssh" and install="github:lmctl-ai/lmssh@latest". Windows is not supported because OpenSSH-portable does not target native Windows.

lmscript --version
lmssh --version
lmssh ssh -V
lmssh --lmcode-schema
lmssh --lmcode-signatures

Commands

lmssh operates both as a direct multi-call wrapper around OpenSSH 10.6p1 client programs and as an LMScript bytecode host supporting dry-run inspection and script argument forwarding.

# Host introspection and bytecode execution
lmssh --version
lmssh --lmcode-schema
lmssh --lmcode-schema --json
lmssh --lmcode-signatures
lmssh --lmcode examples/compiled/fleet-check.dslb
lmssh --dry-run --lmcode examples/compiled/fleet-check.dslb
lmssh --lmcode job.dslb -- web1 web2

# Direct OpenSSH client modes (or via symlinks named ssh, sftp, scp, ssh-keygen)
lmssh ssh -p 2222 -J bastion user@host "uname -a"
lmssh sftp user@host
lmssh scp -r build/ user@host:/srv/app/
lmssh ssh-keygen -t ed25519 -f /tmp/id_ed25519 -N "" -C "ops@example.com"

Inputs and outputs

In _lmcode_ mode, lmssh exposes four host contexts (ssh: Ssh, keys: Keys, io: Io, and report: Report) together with the 226 standard lmcode_std_v3 functions and methods. Script arguments passed after -- are read via io.args(). Remote commands run via Session.exec or Ssh.each return Result and ResultList objects carrying exit status, stdout, stderr, destination name, and timeout flags. At termination, bytecode execution prints any io.print lines followed by a terminal JSON result envelope on stdout.

Safety rules

Follow these operational and security boundaries when authoring lmssh scripts:

Worked examples

The first example generates a Certificate Authority key, a user key, and an SSH user certificate, then signs and verifies a payload file in an isolated temporary directory:

p = _lmcode_ cli="lmssh" install="github:lmctl-ai/lmssh@latest";
let dir = io.temp_dir();
let ca = keys.generate(dir + "/ca_key", "ed25519", "ca@example.com", "");
let user = keys.generate(dir + "/user_key", "ed25519", "alice@example.com", "");
let cert_path = keys.certify(ca.path(), user.path() + ".pub", "alice-id", "alice,deploy", "+52w");
assert_eq(io.exists(cert_path), true);

let payload = dir + "/artifact.txt";
io.write(payload, "release-v1.0.0\n");
let sig_path = keys.sign(user.path(), "file", payload);
let allowed = dir + "/allowed_signers";
io.write(allowed, "alice@example.com " + user.public() + "\n");
assert_eq(keys.verify(allowed, "alice@example.com", "file", sig_path, payload), true);
end _lmcode_
res = run_lmcode(p);
require(res.ok, json_stringify(res));

The second example combines SSH key management with the standard lmcode_std_v3 CliOption, CliCommand, and RestGet interfaces:

p = _lmcode_ cli="lmssh" install="github:lmctl-ai/lmssh@latest";
@"--comment"
fn opt_comment(x: RestExchange) -> void implements CliOption {
  x.set("comment", x.query("comment"));
}

@"keygen"
fn cmd_keygen(x: RestExchange) -> void implements CliCommand {
  let dir = io.temp_dir();
  let k = keys.generate(dir + "/cli-key", x.body(), x.get("comment"), "");
  x.send(k.type() + ":" + k.comment() + ":" + str(k.bits()));
}

@"/keys/ed25519"
fn get_ed25519(x: RestExchange) -> void implements RestGet {
  let dir = io.temp_dir();
  let k = keys.generate(dir + "/rest-key", "ed25519", "rest@lmssh", "");
  x.json("{\"type\":\"" + k.type() + "\",\"bits\":" + str(k.bits()) + "}");
}

rest_config("session", "global");
assert_eq(rest_cli(str_split("--comment=cli@lmssh keygen -- ed25519", " ")), "ed25519:cli@lmssh:256");
assert_eq(rest_cli(str_split("/keys/ed25519", " ")), "{\"type\":\"ed25519\",\"bits\":256}");
end _lmcode_
res = run_lmcode(p);
require(res.ok, json_stringify(res));

Errors and exit codes

In direct OpenSSH mode (lmssh ssh, sftp, scp, ssh-keygen), lmssh returns the exact exit status of the underlying OpenSSH program. In _lmcode_ and host modes, it uses deterministic exit codes:

How to verify

Verify the lmssh binary by checking its host version, embedded OpenSSH version, schema JSON, and canonical signature list against the compiler:

lmssh --version
lmssh ssh -V
lmssh --lmcode-schema --json > /tmp/lmssh-schema.json
lmssh --lmcode-signatures > /tmp/lmssh-sigs.txt
lmscript --lmcode-signatures /tmp/lmssh-schema.json > /tmp/lmssh-compiler-sigs.txt
diff -u /tmp/lmssh-compiler-sigs.txt /tmp/lmssh-sigs.txt

In a source checkout, run ./test.sh to execute all 29 verification checks, including schema parity, dry-run tracing, path injection rejection, and live loopback sshd integration tests.