# Using a static SSH port for Lima VM

**URL:** https://discourse.roots.io/t/using-a-static-ssh-port-for-lima-vm/29886
**Category:** trellis
**Tags:** lima
**Created:** 2025-09-01T21:29:03Z
**Posts:** 3

## Post 1 by @andronocean — 2025-09-01T21:29:03Z

I really like the Lima VMs and have found them to be more reliable than Vagrant, but one thing constantly aggravates me: the SSH port on the host side changes every time the VM is restarted. To use wp-cli aliases, for instance, I have to go through this sequence:

1. `trellis vm start`
2. `limactl list` to check the assigned port number
3. edit my `~/.ssh/config` to update the port
4. confirm it worked with `wp @development acorn about` (or whatever to use SSH…)

I have tried editing the `.trellis/lima/example.com.yml` file to set a static port, for instance:

```
ssh:
  localPort: 59123
  forwardAgent: true
```

… which doesn’t seem to do anything. Lima (or Trellis?) happily ignores it and grabs whatever port it feels like at boot.

There was some discussion a while ago about adding a hard-coded port option: [Introducing Lima to Trellis for Faster Local Development - #18 by swalkinshaw](https://discourse.roots.io/t/introducing-lima-to-trellis-for-faster-local-development/24928/18)

Did anything ever happen with that? Does anyone have a workaround that makes this less painful?

---

## Post 2 by @swalkinshaw — 2025-09-01T22:51:54Z

Have you tried `trellis alias` to generate the WP aliases file? Theoretically that’s at least a nice replacement for steps 2-3 above.

> [@andronocean](#):
>
> I have tried editing the `.trellis/lima/example.com.yml` file to set a static port

You need to edit the Lima config file at `~/.lima/<vm_name>/lima.yaml` and then restart the VM.

`.trellis/lima/example.com.yml` has been removed completely for a while now (see [Refactor Lima config management by swalkinshaw · Pull Request #449 · roots/trellis-cli · GitHub](https://github.com/roots/trellis-cli/pull/449) ) to make config changes like this simpler.

All that being said, I think it should be pretty trivial to support a static port option (since it already exist in Lima) if people want to set it :+1:

edit: oh also, Lima always generates an SSH config at `~/.lima/<vm_name>/ssh.config` that can be used/included in your `~/.ssh/config` file which might make SSH connections via WP-CLI simpler too.

---

## Post 3 by @andronocean — 2025-09-09T15:10:27Z

Aha! That’s very useful.

Using the generated SSH config seems to be the simplest route:

```
# ~/.ssh/config
# Include dynamically generated configs from Lima
Include ~/.lima/<vm_name>/ssh.config
```

Lima defines an SSH host alias like `lima-domain-com`.

I have used `trellis alias`. Haven’t been in the habit of running the `alias` command frequently because the output seemed fixed (I commit it to git for that reason).

Maybe this is a Trellis config issue, but for the local `@development` VM it just outputs `ssh: "domain.test"` and no port at all. The other remote environments do have full `user@ipaddress:port` definitions.

Obviously `ssh: "domain.test"` doesn’t work if Lima’s host alias is `lima-domain-com`. I can edit it manually to `ssh: "lima-domain-com"` and then everything works perfectly — however if `trellis alias` is run again it will undo it. Minor detail if I have it in git, but is there any way to control what trellis puts in there?

> [@swalkinshaw](#):
>
> `.trellis/lima/example.com.yml` has been removed completely for a while now

The curse of long-lived dev environments strikes again :joy:

(Sorry for the slow reply, I was busy with other stuff all last week and didn’t check back in.)
