Skip to content

Remote commands and transfers

Bayesian SSH includes commands to execute scripts across multiple hosts and transfer files in parallel. It handles batch targeting, progress tracking, and automatic fallback between SFTP and SCP.

The bssh exec command runs one-off commands over SSH without opening an interactive shell session.

Always place -- before the remote command to separate bssh flags from command arguments.

Run a command on a specific host:

bssh exec web-prod -- uname -a

When targeting a single host, bssh exec streams stdout and stderr directly to your terminal and exits with the remote process’s exit code.

You can target multiple servers in parallel by tag or run a command across your entire inventory.

Target hosts by tag:

bssh exec -t prod -- systemctl status nginx

Target all saved connections:

bssh exec --all -- uptime

Multi-host execution runs concurrently across up to 16 hosts at a time. Each host’s output is separated by a header block:

🚀 Executing 'uptime' across 2 host(s)...
==================================================
Host: web-prod (deploy@web.example.com)
==================================================
12:45:10 up 45 days, 3:12, 1 user, load average: 0.15, 0.08, 0.02
(Exit Code: 0)
==================================================
Host: db-prod (deploy@10.0.4.12)
==================================================
12:45:10 up 90 days, 14:02, 0 users, load average: 0.42, 0.38, 0.30
(Exit Code: 0)

If a command outputs to stderr, the output is captured in a separate [STDERR] block. If any host fails, bssh exec exits with an error indicating how many hosts failed.

To inspect which hosts will be contacted before executing commands:

bssh exec -t prod --dry-run -- systemctl restart nginx
🔍 [DRY-RUN PREVIEW]
Command to execute: systemctl restart nginx
Target hosts (2):
- web01 (deploy@10.0.4.10)
- web02 (deploy@10.0.4.11)
Dry-run complete. No remote commands were executed.

Use bssh exec [TARGET] -- <COMMAND>... directly from your terminal.

The bssh upload command transfers a local file or directory to one or more remote hosts in parallel.

bssh upload web-prod ./app.tar.gz /opt/app/

You can target hosts explicitly, by tag, or across all saved connections:

  • Comma-separated list:
    bssh upload web1,web2 ./app.tar.gz /opt/app/
  • By tag:
    bssh upload -t prod ./app.tar.gz /opt/app/
  • All saved connections:
    bssh upload --all ./app.tar.gz /opt/app/
  • -r, --recursive: Recursively upload an entire directory tree.
    bssh upload web-prod -r ./config/ /etc/myapp/
  • --mode <OCTAL>: Set remote file permissions (default: 0o644).
    bssh upload web-prod ./deploy-key.pem /root/.ssh/id_rsa --mode 0o600
  • -j, --parallel <N>: Maximum number of concurrent host uploads (default: 16).
    bssh upload -t prod -j 8 ./release.tar.gz /var/www/
  • --offset <BYTES>: Resume an interrupted transfer starting at a byte offset (single-host only).
  • --dry-run: Preview matching hosts and resolved destination paths without transferring files.

When run in an interactive terminal, bssh upload displays multi-bar progress showing byte counts, transfer rates, and estimated time remaining for each host.

bssh uses native SFTP for direct connections. When uploading through a bastion or a Kerberos session, it automatically falls back to SCP. On interactive bastions (such as OVH “The Bastion”), it executes via an auto-generated wrapper script using the --osh scp protocol.

Use bssh upload [OPTIONS] [TARGETS] <LOCAL> <REMOTE> in your terminal.

The bssh download command transfers files or directories from a remote server to your local machine.

bssh download web-prod /var/log/nginx/access.log ./access.log
  • -r, --recursive: Recursively download an entire remote directory tree:
    bssh download db-prod -r /backups/daily/ ./local-backups/

Like uploads, bssh download uses native SFTP on direct connections and falls back to SCP when connecting through bastions or when SFTP subsystems are unavailable.

In interactive terminals, a progress bar shows transfer progress, speed, and completed byte counts.

Flag Commands Description
-a, --all exec, upload Target all saved connections in parallel.
-t, --tag <TAG> exec, upload Target connections carrying this tag.
--dry-run exec, upload Preview target hosts without running or transferring.
-r, --recursive upload, download Recursively process directory trees.
--mode <OCTAL> upload Set remote file permissions (default: 0o644).
-j, --parallel <N> upload Maximum concurrent uploads (default: 16).
--offset <BYTES> upload Resume upload from byte offset (single host only).