# Connect over SSH

> Connect to a flockvm VM with the SSH command from its page, as user or root, set up ~/.ssh/config, copy files, forward ports and use VS Code Remote-SSH.

- URL: https://flockvm.com/docs/vms/ssh
- Section: Virtual machines
- Last updated: 2026-11-10

SSH is how you reach a VM: a shell, file copies, port forwarding and editors all go through it. Each VM has its own port on the host in France, forwarded to the VM's port 22.

## Connect

Open the VM in the dashboard and copy the command from the **Connect** block.

![The Connect block of a VM page, with its copy button](https://flockvm.com/docs/screenshots/vm-ssh.webp "Click Copy to copy the command.")

```bash
ssh -p 22001 user@HOST
```

- `-p 22001` is the VM's own port, between 22001 and 22990. It stays the same for the VM's whole life, through pause, resume, stop and start.
- `HOST` is the host of the VM's region, as written on the VM page.
- `user` is the user on the Agent image. On the Minimal image, it is `root`, and the command reads `ssh -p 22001 root@HOST`. Logins are by key only: passwords and keyboard-interactive logins are off.

The page also says where the port goes, for example "Port 22001 on HOST goes to 172.16.0.2:22. Log in as user with the key you gave at creation."

| Image                        | SSH user | Home         | Root access                                                                  |
| ---------------------------- | -------- | ------------ | ---------------------------------------------------------------------------- |
| Agent (`ubuntu-26.04-agent`) | `user`   | `/home/user` | `sudo`, without a password; logging in as `root` with the same key works too |
| Minimal (`ubuntu-26.04`)     | `root`   | `/root`      | You are root                                                                 |

A VM created before 2026-11-01 on Ubuntu 24.04 (`ubuntu-24.04-agent` or `ubuntu-24.04`) keeps the same login: `user` on the old Agent image, `root` on the old Minimal. See [Images](https://flockvm.com/docs/vms/images#vms-created-on-ubuntu-2404).

The examples below use `user@HOST` and `/home/user`. On a Minimal VM, write `root@HOST` and `/root`.

> **Note:** The command works only while the VM is `running`. A paused VM's page says "Paused. Resume it and the same command works, with the same processes." See [Lifecycle](https://flockvm.com/docs/vms/lifecycle).

If your key is not the default `~/.ssh/id_ed25519`, name it:

```bash
ssh -i ~/.ssh/flockvm_ed25519 -p 22001 user@HOST
```

## Add the VM to \~/.ssh/config

An entry saves you typing the port, the user and the key. Use the host and port from the VM page, and `User root` for a Minimal VM.

```ssh-config title="~/.ssh/config"
Host agent
  HostName HOST
  Port 22001
  User user
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes
  ServerAliveInterval 30
  ServerAliveCountMax 4
```

Then:

```bash
ssh agent
```

`ssh`, `scp`, `rsync`, `git` and editors all read this file, so every command below works with the alias.

> **Tip: Several VMs.** Add one `Host` block per VM, each with its own `Port`. Shared settings can go in a `Host *` block at the end, or in a block that matches all of them, such as `Host agent-*`.

## Copy files

`scp` takes the port with a capital `-P`. `rsync` takes it through `-e`.

**scp:**

```bash title="scp"
# Upload a file
scp -P 22001 ./notes.md user@HOST:/home/user/

# Download a folder
scp -P 22001 -r user@HOST:/home/user/app/dist ./dist
```

**rsync:**

```bash title="rsync"
# Sync a project, skipping node_modules
rsync -az --delete --exclude node_modules \
  -e "ssh -p 22001" ./my-app/ user@HOST:/home/user/my-app/
```

**With the alias:**

```bash title="With the alias"
scp ./notes.md agent:/home/user/
rsync -az -e ssh ./my-app/ agent:/home/user/my-app/
```

`rsync` is installed in both images, so both ends have it.

## Clone a private repository

The VM has outbound internet access, so `git clone` over HTTPS works with a token. Over SSH, add a deploy key to the VM, or use agent forwarding (below) with care.

```bash
ssh agent
git clone https://github.com/your-org/your-repo.git
```

## Forward a port

A VM has no public HTTP port: only SSH comes in. To open a dev server running in the VM, forward its port to your machine with `-L`.

```bash
# The VM's localhost:3000 becomes your localhost:3000
ssh -N -L 3000:localhost:3000 agent
```

Open `http://localhost:3000` in your browser. `-N` keeps the connection open without a shell. Forward several ports by repeating `-L`.

In `~/.ssh/config`:

```ssh-config title="~/.ssh/config"
Host agent
  # …
  LocalForward 3000 localhost:3000
  LocalForward 5173 localhost:5173
```

To show the server to someone else, see [Networking](https://flockvm.com/docs/vms/networking#show-a-dev-server).

## VS Code and Cursor

Remote-SSH in VS Code and Cursor reads `~/.ssh/config`.

1. **Add the config entry**

   Add the `Host agent` block above to `~/.ssh/config`.

2. **Connect**

   Open the command palette (`⌘⇧P` or `Ctrl+Shift+P`), run **Remote-SSH: Connect to Host…** and pick `agent`.

3. **Open a folder**

   The editor installs its server in the VM on first connection, then opens your home folder (`/home/user` or `/root`) or the folder you pick.

The editor server lives on the VM's disk, so it is still there after a stop and start. Its memory counts in the VM's RAM: on a `small` VM (4 GB), keep an eye on the **Memory** tile of the VM page.

## Keep sessions alive

The VM's `sshd` sends a keepalive every 30 seconds (`ClientAliveInterval 30`). Add `ServerAliveInterval` on your side too, so idle sessions survive NAT and Wi-Fi changes:

```ssh-config title="~/.ssh/config"
Host *
  ServerAliveInterval 30
  ServerAliveCountMax 4
```

A dropped connection still kills the shell's processes. Run long jobs and agents in `tmux`, which is installed in both images:

```bash
ssh agent -t tmux new -A -s main
```

See [Long-running sessions with tmux](https://flockvm.com/docs/agents/tmux).

> **Info: Pause keeps your session.** When you pause a VM, open SSH connections stall. After **Resume**, the VM has the same processes, address and port, and a connection that did not time out meanwhile carries on.

## Agent forwarding

`ssh -A` lets the VM use the keys of your local SSH agent, for example to `git push` over SSH.

```bash
ssh -A agent
ssh -T git@github.com
```

> **Warning: Forward your agent only to VMs you trust.** While you are connected, anything running as your user or as root in the VM, a coding agent included, can ask your local agent to sign with your keys. Prefer a deploy key or a fine-grained token scoped to one repository for agents.

## Host key changes

Each VM generates its own SSH host keys (ed25519 and ecdsa) on its first boot. They stay the same through pause, resume, stop and start.

When you delete a VM and create a new one, the new VM has new host keys. flockvm does not hand a deleted VM's port to the next VM right away, but ports are reused eventually. When a new VM gets a port you used before, SSH refuses to connect:

```text
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
```

If you deleted the old VM yourself, remove its entry and connect again:

```bash
ssh-keygen -R "[HOST]:22001"
```

For short-lived VMs you create and delete often, accept new host keys automatically but still refuse changed ones:

```ssh-config title="~/.ssh/config"
Host agent-*
  StrictHostKeyChecking accept-new
```

> **Danger:** Don't set `StrictHostKeyChecking no` for VMs you keep. A host key that changes on a VM you did not delete is worth a look.

## Troubleshooting

### Permission denied (publickey)

The key you offer is not the one given at creation. Pass the private key that matches the key you picked in the **New VM** form with `-i`, and compare fingerprints with `ssh-keygen -lf ~/.ssh/id_ed25519.pub` against the one listed in your account settings. Keys you add to your account later don't reach existing VMs: see [SSH keys](https://flockvm.com/docs/vms/ssh-keys#add-a-key-to-a-running-vm).

After repeated failed logins from your address, the VM's SSH server (OpenSSH 10, on the Ubuntu 26.04 images) closes new connections from that address for a while, from a few seconds up to 10 minutes. Fix the key, wait, then connect again.

### Connection refused or timeout

The VM is not `running`. Check its status on the VM page: start or resume it, then connect again.

### The VM rebooted and now it's stopped

A `reboot` or `poweroff` inside the VM stops it. Click **Start** on the VM page. See [Lifecycle](https://flockvm.com/docs/vms/lifecycle#reboot-and-poweroff-inside-the-vm).

More in [Troubleshooting](https://flockvm.com/docs/resources/troubleshooting).

## Next steps

- [SSH keys](https://flockvm.com/docs/vms/ssh-keys): Generate, save and add keys.
- [Networking](https://flockvm.com/docs/vms/networking): What goes in and out of a VM.
- [tmux sessions](https://flockvm.com/docs/agents/tmux): Keep agents running after you disconnect.
