ssh_exec
Execute a single remote command via SSH and retrieve stdout, stderr, and exit code. Ideal for non-interactive tasks requiring remote directory or environment setup.
Instructions
Run a one-off remote SSH command and return stdout, stderr, and exit metadata. The command runs in a non-interactive context. Use 'cwd' and 'env' for remote directory and environment setup (requires a POSIX shell on the remote). For interactive or long-running commands, use ssh_ensure_session instead.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Remote directory to cd into before running the command. | |
| env | No | Remote environment variables exported before the command runs. | |
| tty | No | Request a remote TTY (ssh -tt). Required for interactive commands (sudo with password prompt, etc.). Avoid for scripted commands: stdout and stderr are merged and ANSI escape codes will be present in output. Default: false. | |
| port | No | ||
| shell | No | Remote shell executable used to wrap the command when shell/cwd/env behavior is needed. | |
| target | Yes | OpenSSH target such as host, alias, or user@host. | |
| command | Yes | Remote command string to execute. | |
| timeout | No | Local timeout in seconds. | |
| identity_file | No | ||
| extra_ssh_args | No | Additional ssh(1) flags passed verbatim, e.g. ["-J", "jumphost"]. Prefer the dedicated port, identity_file, and strict_host_key_checking parameters. | |
| known_hosts_file | No | ||
| strict_host_key_checking | No | Boolean or one of yes, no, ask, accept-new, off. |