# Connect with plain ssh

Each server has its own host and port, which change when it is recreated or moved. Instead of copying them every time, the `apidly` command can write them into your SSH config file. After that, `ssh my-gpu` works, and so do `scp`, `rsync` and editors that read `~/.ssh/config`. You need the `apidly` command (see [Use the CLI and API from scratch](/docs/tutorial-cli-and-api)), a running server and your SSH key added under **SSH keys** (see [Connect with SSH](/docs/connect-ssh)).

## 1. Look at the entries first

```bash
apidly ssh-config
```

This only prints, and changes nothing. For each running server that answers SSH you see an entry like this:

```text
Host ins_abc123 my-gpu
  HostName 203.0.113.10
  Port 40022
  User root
  StrictHostKeyChecking accept-new
  ServerAliveInterval 60
```

The first name is the server id. The second is the server's label, in lower case with spaces and other characters turned into `-`. A label is added only when no other running server has the same one. If your private key is not in the default place, add `-i ~/.ssh/your_key`: each entry then gets an `IdentityFile` line.

## 2. Write them into your SSH config

```bash
apidly ssh-config --write
```

You see `Wrote 1 server to …/.ssh/config. Connect with ssh my-gpu.` The entries go into one marked block:

```text
# >>> apidly servers (written by `apidly ssh-config --write`; edits inside are replaced) >>>
…
# <<< apidly servers <<<
```

Everything outside the block is kept as it was. Do not edit inside it: the next run replaces the whole block. To write another file, add `--file PATH`.

## 3. Connect by name

```bash
ssh my-gpu
scp results.csv my-gpu:/workspace/
rsync -av ./data/ my-gpu:/workspace/data/
```

The first time, ssh accepts the server's host key on its own (`StrictHostKeyChecking accept-new`), and it refuses a changed key later. In VS Code or Cursor, the server appears under Remote-SSH by the same name.

## 4. Run it again when servers change

Only running servers are written. After you start, stop, recreate or deploy a server, run `apidly ssh-config --write` again so the block matches.

## Remove the block

Stop the servers you no longer need, then run `apidly ssh-config --write`. When no server is running, it removes the apidly block and says so. You can also delete the lines from `# >>> apidly servers` to `# <<< apidly servers <<<` in `~/.ssh/config` by hand; nothing else depends on them.

## What it costs and how to stop spending

Writing the config costs nothing. The server you connect to is billed by the second while it runs. When you are done, stop it with `apidly stop ins_ID` (the disk is still charged) or destroy it with `apidly destroy ins_ID`.

## Next

- [Connect with SSH](/docs/connect-ssh)
- [Using VS Code and Cursor over SSH](/docs/vscode-and-cursor)
