Skip to content

Need help?

Reach out to us on Discord

Discord

dstack attach

This command attaches to a given run. It establishes the SSH tunnel, forwards ports, and shows real-time run logs.

Usage

$ dstack attach --help
Usage: dstack attach [-h] [--project NAME] [--ssh-identity SSH_PRIVATE_KEY]
                     [--logs] [--host HOST] [-p MAPPING] [--replica REPLICA]
                     [--job JOB] [--since SINCE]
                     run_name

Positional Arguments:
  run_name

Options:
  -h, --help            Show this help message and exit
  --project NAME        The name of the project. Defaults to $DSTACK_PROJECT
  --ssh-identity SSH_PRIVATE_KEY
                        The private SSH key path for SSH tunneling
  --logs                Print run logs as they follow
  --host HOST           Local address to bind. Defaults to localhost.
  -p, --port MAPPING    Port mapping overrides
  --replica REPLICA     The replica number. Defaults to any running replica.
  --job JOB             The job number inside the replica. Defaults to 0.
  --since SINCE         Show only logs newer than the specified date. Can be a
                        duration (e.g. 10s, 5m, 1d) or an RFC 3339 string
                        (e.g. 2023-09-24T15:30:00Z).

User SSH key

By default, dstack attaches to runs using the user's SSH key automatically created and managed by dstack. The CLI downloads it from the server and stores it under ~/.dstack/ssh/. To attach with a different key, pass the path to its private key via --ssh-identity. If the run was submitted with dstack apply --ssh-identity, pass the same key.

SSH proxy

If the SSH proxy is configured, you can also use any key uploaded under SSH keys in the user settings.