Changes permission bits on one or more paths (chmod). A numeric mode is rendered
as octal; a string mode (e.g. 'u+x') is passed through. Paths follow --.
A path or array of paths.
Numeric mode (rendered octal) or a symbolic/string mode.
Optionalopts: { recursive?: boolean }
recursive adds -R.
Nothing on success.
Closes the session and underlying transport.
Reports filesystem usage via df -Pk (POSIX 1K-block columns).
Optionalpath: string
Optional path to limit the report to its filesystem.
One row per filesystem with sizes in kibibytes and the use percentage.
Runs a command and resolves with its captured output and exit code.
Runs a command on a fresh session channel and returns the live duplex handle without
waiting for it to finish, so you can stream write() to its stdin, read stdout/
stderr as they arrive, and await its exit. Use this when you need to interact
with the command (feed it stdin, react to partial output) rather than just collect a
final result - exec is the collect-to-completion shortcut over this.
The command line to run (interpreted by the remote login shell).
The live channel handle.
await using ssh = await connect({ hostname: 'h', username: 'u', password: 'p' });
await using ch = await ssh.execStream('cat'); // echoes stdin back on stdout
await ch.write(new TextEncoder().encode('hello\n'));
await ch.eof();
const reader = ch.stdout.getReader();
const { value } = await reader.read();
console.log(new TextDecoder().decode(value)); // "hello"
await ch.exit;
Opens a direct-tcpip tunnel: the server connects to host:port on your behalf and
pipes the bytes back over a duplex channel (the -L-style reach-through). Use it to
reach a service - a database, an internal API - that sits behind an SSH bastion.
The target host the server should connect to.
The target port.
A duplex channel: stdout is inbound bytes, write() sends outbound.
Creates a directory and any missing parents (mkdir -p).
The directory to create.
Optionalopts: { mode?: number }
mode sets the octal permission bits (passed as mkdir -m).
Nothing on success.
Forces a key re-exchange now; resolves when new keys are installed.
Removes one or more paths (rm). Each target is checked by an internal guard that
refuses empty, /, ~, ., and .., then the paths are passed after -- so a
leading-dash name cannot be read as a flag.
A path or array of paths to remove.
Optionalopts: { force?: boolean; recursive?: boolean }
recursive adds -r; force adds -f.
Nothing on success.
Runs a command, decodes its stdout as UTF-8, and returns it. Throws when the command exits nonzero, putting the exit code and the decoded stderr in the error message.
The command is interpreted by the remote login shell, so quote/escape it yourself if it interpolates untrusted values (the typed helpers like mkdirp do this for you via single-quote wrapping).
The typed helpers (mkdirp/rm/chmod/stat/df/
which/readTextFile/writeTextFile/spawnDetached) assume a
POSIX shell, so they work against Linux, macOS, and other Unix remotes (stat and
spawnDetached handle the GNU/BSD differences). For a Windows (cmd.exe/PowerShell) or
other non-POSIX remote, use run/exec/execStream directly with native commands.
The command line to run.
Optionalopts: { trim?: boolean }
trim strips leading/trailing whitespace from stdout (default true).
The command's decoded stdout.
Opens an interactive shell channel.
Launches a command detached so it outlives the SSH channel, with stdin closed and
stdout/stderr redirected (default /dev/null). Uses nohup (POSIX; works on Linux and
macOS, unlike the Linux-only setsid). Returns once the launcher returns; it does not
wait for the spawned process.
The command to run in the background.
Optionalopts: { stderr?: string; stdout?: string }
stdout/stderr redirect targets (default /dev/null).
Nothing once the process is launched.
Stats a single path. Portable across GNU (Linux) stat -c and BSD (macOS) stat -f:
it tries the GNU form and falls back to the BSD form, then normalizes both.
The path to stat.
Size in bytes, numeric mode (the full st_mode), mtime in epoch seconds,
and isDirectory/isSymlink flags.
Runs a command and reports whether it succeeded (exit code 0). Never throws on a
nonzero exit - that maps to false - so it reads cleanly as a predicate.
The command line to run.
true if the command exited 0, else false.
Writes text to a file by streaming the bytes to cat's stdin, so the payload is never
shell-quoted. Truncates by default; append appends instead (cat >>).
The file to write.
The text to write (UTF-8 encoded onto stdin).
Optionalopts: { append?: boolean }
append appends rather than truncating.
Nothing on success.
A stateful SSH session.