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:
trellis vm start
limactl list to check the assigned port number
- edit my
~/.ssh/config to update the port
- 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
Did anything ever happen with that? Does anyone have a workaround that makes this less painful?
Have you tried trellis alias to generate the WP aliases file? Theoretically that’s at least a nice replacement for steps 2-3 above.
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 ) 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 
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.
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?
The curse of long-lived dev environments strikes again 
(Sorry for the slow reply, I was busy with other stuff all last week and didn’t check back in.)