> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# nsc ssh

Connect to ephemeral environments.

`ssh` connects to a previously created ephemeral environment. It establishes a
`ssh` connection to the target environment, over Namespace's networking, in a
way that end-to-end encryption is retained, but the target host is not exposed
directly to the Internet.

To enable experimentation, `ssh` also has a "quick create" mode built-in,
allowing you to quickly create a named environment (a sandbox), or get back to a
previously created sandbox.

This allows you to jump into a container-enabled terminal in a few seconds.

## Usage

```bash theme={null}
nsc ssh [--container_name <name>] [-T] [-t] [--oneshot] [-A] [--unique_tag <name>] [<id>] [command]
```

### Example

<Steps titleSize="h4">
  <Step title="Create an ephemeral instance">
    Create an ephemeral instance and note its ID:

    ```bash theme={null}
    nsc create
    ```

    ```text nocopy Output theme={null}
    Created new ephemeral environment! ID: 85a32emcg99ii
    ```
  </Step>

  <Step title="Connect to the instance">
    Connect to the instance using its ID:

    ```bash theme={null}
    nsc ssh 85a32emcg99ii
    ```

    ```text nocopy Output theme={null}
    85a32emcg99ii:~#
    ```
  </Step>

  <Step title="Select an instance interactively">
    Omit the instance ID to select from a list of your instances:

    ```bash theme={null}
    nsc ssh
    ```

    ```text nocopy Output theme={null}
    ┌─────────────────────────────────────────────────────────────────────────────────┐
    │ Instance ID    CPU  Memory   Arch   Created       Time to live         Purpose  │
    │─────────────────────────────────────────────────────────────────────────────────│
    │ 85a32emcg99ii  4    4.0 GiB  amd64  10 hours ago  29 minutes from now  ...      │
    └─────────────────────────────────────────────────────────────────────────────────┘
    ```
  </Step>

  <Step title="Run a remote command">
    Run a command directly in the instance through `nsc ssh`:

    ```bash theme={null}
    nsc ssh 85a32emcg99ii ls /
    ```

    ```text nocopy Output theme={null}
    bin         etc         lib         media       nsc         proc        run         srv         tmp         var
    dev         home        lost+found  mnt         opt         root        sbin        sys         usr         vendor
    ```
  </Step>
</Steps>

## Options

<h3 id="--container_name-name">
  \--container\_name \<name>
</h3>

Connects to the container named `name` in the environment, instead of the
instance environment itself.

On a GitHub Actions runner instance, use `--container_name github-runner` to
connect to the runner container while it is handling a job.

<h3 id="--disable-pty--t">
  \--disable-pty, -T
</h3>

Disables allocation of a pseudo-terminal for the SSH session. This is useful
when running a non-interactive command whose output you're piping elsewhere,
where a TTY would otherwise introduce unwanted formatting.

<h3 id="--force-pty--t">
  \--force-pty, -t
</h3>

Forces allocation of a pseudo-terminal, even when running a non-interactive
command. This is useful for commands that expect a terminal to be present,
such as ones that produce colored output or otherwise behave differently
without one.

<h3 id="--oneshot">
  \--oneshot
</h3>

If specified, a temporary instance is created for the SSH session and
destroyed as soon as you disconnect. This is convenient for quick, one-off
experiments where you don't want the instance to stick around afterward.

<h3 id="--ssh_agent--a">
  \--ssh\_agent, -A
</h3>

Forward your local SSH agent connection, to the remote environment.

<h3 id="--unique_tag-name">
  \--unique\_tag \<name>
</h3>

If specified, creates an instance with the specified unique tag, so you can
identify or reference that specific environment later.
