# Editors and plain SSH

> For the complete documentation index, see [llms.txt](https://docs.ringleader.dev/llms.txt).


> Ringleader keeps an SSH configuration for every workstation you can reach, so SSH tools and your editor connect by name.


Ringleader keeps an SSH configuration for every workstation you can reach, so SSH tools and
your editor connect by name. `ssh`, `scp`, `rsync`, `git`, JetBrains Gateway, Ansible and the
Remote-SSH extension of VS Code or Cursor then work with no `rl` in the loop. A workstation can
also run VS Code itself, which you open in a browser tab.

## Ringleader's SSH configuration

While the Ringleader background service runs, it writes an OpenSSH configuration for every
workstation you can reach. It rewrites that configuration as workstations are created,
started, stopped and deleted. You add it to your own SSH configuration once, with one
`Include` line.

That line points at Ringleader's `~/.ringleader/ssh/config`, which includes one `.conf` file
for each workstation. The service owns these files and regenerates them on every change. Each
file carries:

- The workstation's current address, port and login user, refreshed when they change.
- A key that Ringleader keeps on your computer, as the `IdentityFile`, with
  `IdentitiesOnly yes`, so none of your own keys are offered.
- A `known_hosts` file of its own for the workstation, with the host key recorded once
  Ringleader has confirmed it. Your own `~/.ssh/known_hosts` is never touched, and creating a
  workstation again under the same name can't produce a host-key-changed warning.
- Connection sharing (`ControlMaster`), so repeated commands reuse one connection instead of
  starting a new one. Windows doesn't get it, because the Windows OpenSSH client doesn't
  support it.

The configuration is only as fresh as the background service. When `rl daemon` isn't running,
the files keep their last state, and a workstation that changed address since then doesn't
connect. `rl daemon status` shows whether it runs.

<div class="callout callout-warning">
  <p class="callout-title">Never edit a generated file</p>
  <div class="callout-body">
    Your edits to a workstation&rsquo;s <code>.conf</code> file are overwritten, and deleting a workstation deletes
its file.
  </div>
</div>


## Names for a workstation

Each workstation answers to three host names: the bare name (`my-box`), the name with
its namespace (`my-box.local`) and a fully qualified form
(`my-box.local.ringleader`). The `.ringleader` suffix doesn't resolve as a real
domain, so the qualified form can never hide a real host.

The bare name claims that name in your SSH configuration. A workstation called `prod` would
hide a `Host prod` of your own. When in doubt, use the `<name>.<namespace>.ringleader` form.

## Position of the include

OpenSSH keeps the first value it reads for each setting, and an `Include` after a `Host` line
applies to that host alone. So an `Include` below your own rules can lose. A `Host *` block
with an `IdentityFile` above it makes `ssh` offer your key instead of Ringleader's, and the
workstation refuses it.

<div class="callout callout-warning">
  <p class="callout-title">An Include at the end might never be read</p>
  <div class="callout-body">
    An <code>Include</code> at the end of the file might never be read, and then <code>ssh</code> offers the wrong key.
  </div>
</div>


Put the `Include` line above every `Host` and `Match` block. `rl ssh-config install` does
that, and when the block sits in the wrong place, running it again moves the block back to
the top. [`rl ssh-config`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-ssh-config) lists what
`status` reports about the position.

## The rl code command

`rl code` opens a workstation in VS Code, Cursor or VS Code Insiders on your computer, over
Remote-SSH. It addresses the workstation by its `<name>.<namespace>.ringleader` name and opens
the first path of `spec.sources` in the resolved configuration. With no sources, the editor
connects with no folder open. It picks the first editor it finds, in the order `code`,
`cursor`, `code-insiders`. When it finds no editor command, `rl code` opens the editor
through its URL handler instead, and fails if nothing on your computer opens the editor's
links.

Remote-SSH runs your system `ssh` and reads your own `~/.ssh/config`, so Ringleader's
`Include` must be there. Before the editor opens, `rl code` runs `ssh -G` with the
workstation's `<name>.<namespace>.ringleader` name to see whether `ssh` finds a host by it.
If `ssh` finds none, `rl code` opens nothing, prints one line that says why and what to do
next, and exits with status `3`. The line names one of three fixes:

- Run `rl ssh-config install`, when the `Include` is missing, in the wrong place, or points
  at another data directory.
- Make sure `rl daemon` is running and the workstation is Running, when Ringleader hasn't
  written the workstation's SSH configuration yet.
- Run `rl ssh-config status` to see why, in any other case.

In three cases, `rl code` doesn't refuse. It warns instead if the `Include` looks wrong, or if
Ringleader hasn't written the workstation's SSH configuration yet:

- `ssh` is missing, fails, or doesn't answer within five seconds. `rl code` opens the editor.
- The editor's user settings mention `remote.SSH.configFile` or `remote.SSH.path`, which make
  Remote-SSH read another SSH configuration or run another `ssh`. `rl code` skips `ssh -G`
  and opens the editor.
- You pass `--print`. `rl code` skips `ssh -G`, prints the command and launches nothing.

The editor also needs its Remote - SSH extension. `rl code` warns when the extension is
missing, and still opens the editor. As it opens the editor, `rl code` prints a line that
names what the window shows once it connects: `SSH: my-box.local.ringleader` in the
bottom-left corner. That is how you tell a window on the workstation from one on your own
computer.

The first time you connect, VS Code downloads its own server, about 100 MB, onto the
workstation from `update.code.visualstudio.com`. A workstation whose outbound access is
restricted can sit at "Setting up SSH Host" until that download completes.

To set editor settings on the workstation before you first connect, use the
[`vscode-server` toolconfig](https://docs.ringleader.dev/reference/tools/tool-configuration/vscode-server/).

## VS Code in a browser

The `vscode-web` devtool installs code-server, which is VS Code in a browser tab, on the
workstation. Only the port forward from your computer reaches it, so you can turn off its
password with `auth: none`.

VS Code in a browser needs three things in the workstation's configuration:

- The `vscode-web` devtool, which installs it.
- The `vscode-web` toolconfig, which tells it how to run.
- A forward for its port, which a `defaultLocalBinding` provides.

[vscode-web](https://docs.ringleader.dev/reference/tools/devtools/vscode-web/) lists its extensions, says how
it starts and where it listens, and names the distributions it supports.

## Connect your own SSH tools

To use `ssh`, `scp`, `rsync` or `git` with a workstation, follow
[Connect to a workstation with SSH](https://docs.ringleader.dev/guides/connect-with-ssh/). It adds the
`Include` line from the application or the command line, and shows how to check and remove
it.

## Open a workstation in your editor

To open a workstation in your editor, add Ringleader's SSH configuration as
[Connect your own SSH tools](#connect-your-own-ssh-tools) describes, then run:

```bash
rl code my-box -n local
```

To choose the editor or the folder, add `--editor cursor` or `--path /home/dev/other-repo`.
Add `--print` to see the command without launching anything.

## Set up VS Code in your browser

To run VS Code in a browser tab, add the devtool, the toolconfig, a declared port and a
forward to a WorkstationConfig. The file selects your workstations by label:

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: WorkstationConfig
metadata:
  name: browser-ide
  namespace: local
spec:
  selector:
    matchLabels:
      ide: browser
  devtools:
    - name: vscode-web
  toolconfigs:
    - id: vscode-web
      name: vscode-web
      config:
        auth: none
  ports:
    - 8080
  defaultLocalBinding:
    enabled: true
    autoForward:
      forwardAll: true
```

Apply the file, and wait until the workstation is `Configured`. Then open
`http://127.0.0.1:8080` on your computer. That is the workstation's VS Code.

If that is all you need, you are done. The next two sections add a password and move the port.

## Require a password for VS Code in a browser

To ask for a password, store it as a Secret, then point the toolconfig at it:

```bash
rl secret create vscode-web-password -n local \
  --from-string vscode-web-password=<choose-a-password>
```

```yaml
toolconfigs:
  - id: vscode-web
    name: vscode-web
    config:
      auth: password
      password: "${secret:vscode-web-password}"
```

Changing the password later restarts code-server for you, because it reads the password only
when it starts.

## Change the port of VS Code in a browser

If something else on the workstation already uses port 8080, move code-server off it. Set
`port` and `auth` together, and declare both ports:

```yaml
toolconfigs:
  - id: vscode-web
    name: vscode-web
    config:
      port: 8081
      auth: none
ports:
  - 8080          # your app
  - 8081          # the IDE
```

<div class="callout callout-warning">
  <p class="callout-title">Set auth with port</p>
  <div class="callout-body">
    Set <code>auth</code> whenever you set <code>port</code>, or nobody can sign in.
  </div>
</div>


[`config` fields](https://docs.ringleader.dev/reference/tools/tool-configuration/vscode-web/#config-fields) says why and
lists the other fields.

Tool configuration is applied before your provisioning scripts run, so code-server has already
moved by the time a script starts your app on 8080.

## Next steps

- [Connect to a workstation with SSH](https://docs.ringleader.dev/guides/connect-with-ssh/) adds
  Ringleader's SSH configuration to yours, and checks or removes it.
- [`rl ssh-config`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-ssh-config) describes every form of
  the command, what `install` writes and how to read `status`.
- [`rl code`](https://docs.ringleader.dev/reference/cli/commands/workstation-access/#rl-code-workstation) lists the flags of the
  editor command.
- [vscode-web](https://docs.ringleader.dev/reference/tools/tool-configuration/vscode-web/) lists the toolconfig's
  fields and editor settings.
- [Port and socket forwarding](https://docs.ringleader.dev/workstations/connectivity/port-socket-forwarding/)
  explains the forward that VS Code in a browser relies on.

