# Sync script & SSH access with Lima

**URL:** https://discourse.roots.io/t/sync-script-ssh-access-with-lima/26927
**Category:** bedrock
**Tags:** lima
**Created:** 2024-04-02T21:31:28Z
**Posts:** 19

## Post 1 by @joshb — 2024-04-02T21:31:28Z

Hey ya’ll… I found this:

[https://discourse.roots.io/t/tweaks-for-sync-script-with-trellis-and-lima/26715/2](https://discourse.roots.io/t/tweaks-for-sync-script-with-trellis-and-lima/26715/2)

And attempting to connect to Lima without any luck.

```
✅ Able to connect to production
❌ Unable to connect to development Error: Cannot connect over SSH using provided configuration.
```

Not sure I am setting up my ssh line for development correctly. Anyone have any pointers or can help guide me?

---

## Post 2 by @ben — 2024-04-02T21:51:57Z

You can use `trellis alias` to generate the correct WP-CLI aliases

---

## Post 3 by @joshb — 2024-04-03T16:51:14Z

Great. I see it created `wp-cli.trellis-alias.yml` and then I copied the development lines over to `wp-cli.yml`.

It’s still able to connect to production and now it takes a lot longer to attempt to connect to development but eventually fails with the same error.

Running `wp @development` or `wp @production` results in:  
`Error: Cannot connect over SSH using provided configuration.`

---

## Post 4 by @ben — 2024-04-03T18:33:35Z

What does your aliases file look like?

What’s the error if you try to SSH into the VM using the same details from the alias?

---

## Post 5 by @joshb — 2024-04-03T19:15:55Z

`trellis alias` generated this for the development lines without any user defined.

```
@development:
  ssh: "newproject.test"
  path: "/srv/www/newproject.com/current/web/wp"
```

WIth vagrant, it would be `vagrant@newproject.test` right?

Not sure what I should be using here for Lima.

* * *

Running `limactl show-ssh -f config newproject.com` shows the user as my macOS username `joshb` as does the inventory file. I’ve tried using that as my user and it just hangs.

---

## Post 6 by @joshb — 2024-04-03T19:39:51Z

`ssh joshb@newproject.test` just hangs and eventually times out.

`trellis vm shell` immediately connects:

```
joshb@lima-client:/srv/www/newproject.com/current$
```

---

## Post 7 by @joshb — 2024-04-03T19:50:50Z

Alright, finally figured it out and connected via the sync script.

Need to us your macOS username@lima-[lima instance name], like so:

```
ssh joshb@lima-newproject.com
```

Trellis alias did not do that correctly afaict.

---

## Post 8 by @ben — 2024-04-03T22:15:55Z

Glad you’re up and running!

I tested a fresh Lima install and using the generated file from `trellis alias`, which worked without any modifications — it’s possible there’s something in your SSH config that’s conflicting with it

---

## Post 9 by @joshb — 2024-04-04T02:12:55Z

It worked without supplying a user?

---

## Post 10 by @intelligence — 2024-04-23T12:10:14Z

Thanks for sharing the details how you got it to work!

---

## Post 11 by @visualasparagus — 2024-06-21T13:03:27Z

I’m trying to get the development alias to work and have tried all of the above but nothing seems to work.

`trellis vm shell` works fine and connects to `systemuser@lima-projectname`

also `ssh -F /Users/systemuser/.lima/projectname.com/ssh.config lima-projectname.com` works fine and connects to `systemuser@lima-projectname`

Here is the contents of the ssh.config file.

```
# This SSH config file can be passed to 'ssh -F'.
# This file is created by Lima, but not used by Lima itself currently.
# Modifications to this file will be lost on restarting the Lima instance.
Host lima-projectname.com
  IdentityFile "/Users/systemuser/.lima/_config/user"
  IdentityFile "/Users/systemuser/.ssh/id_ed25519"
  IdentityFile "/Users/systemuser/.ssh/id_rsa"
  StrictHostKeyChecking no
  UserKnownHostsFile /dev/null
  NoHostAuthenticationForLocalhost yes
  GSSAPIAuthentication no
  PreferredAuthentications publickey
  Compression no
  BatchMode yes
  IdentitiesOnly yes
  Ciphers "^aes128-gcm@openssh.com,aes256-gcm@openssh.com"
  User systemuser
  ControlMaster auto
  ControlPath "/Users/systemuser/.lima/projectname.com/ssh.sock"
  ControlPersist yes
  ForwardAgent yes
  Hostname 127.0.0.1
  Port 62290
```

however, I cannot seem to setup the alias in such a way that it will connect.

I’ve tried the following:

```
@development:
  ssh: "systemuser@lima-projectname.com"
```

This returns `Error: Cannot connect over SSH using provided configuration.`

and `ssh systemuser@lima-projectname.com` returns `ssh: Could not resolve hostname lima-projectname.com: nodename nor servname provided, or not known`

```
@development:
  ssh: "systemuser@projectname.test"
```

This returns `Error: Cannot connect over SSH using provided configuration.`

and `ssh systemuser@projectname.text` just returns without any message

```
@development:
  ssh: "-F /Users/systemuser/.lima/projectname.com/ssh.config lima-projectname.com"
```

returns `hostname contains invalid characters`

Any help would be appreciated.

Thanks!

---

## Post 12 by @visualasparagus — 2024-06-25T10:22:09Z

So I seem to have figured out at least one way to do it.

Looking at how the output of `limactl show-ssh mysite.com` it seems that you can connect to 127.0.0.1 on port 62290. So I changed my wp-cli.yml to be the following

```
@development:
  ssh: "systemuser@127.0.0.1:62290"
  path: "/srv/www/mysite.com/current/web/wp"
```

I hope this helps someone.

---

## Post 13 by @visualasparagus — 2024-06-27T09:02:01Z

So it seems the port number is regenerated each time the Lima VM is recreated. Would be great to know to connect via lima.

---

## Post 14 by @joaovpmamede — 2024-06-29T17:01:18Z

What I did was add to `~/.ssh/config` this line:  
`Include /Users/<username>/.lima/example.test/ssh.config`

Then on `wp-cli.yml` I have:

```
"@development":
  ssh: "lima-example.test"
  path: "/srv/www/example.test/current/web/wp"
```

---

## Post 15 by @visualasparagus — 2024-07-01T08:56:17Z

Hi @joaovpmamede,

Thanks! Although this did not work for me it did lead me to some old vagrant specific line items in my `~/.ssh/config` file. Once I removed these, then I could just use `systemuser@project-name.test` in the wp.cli file to connect.

---

## Post 17 by @dalepgrant — 2025-01-21T00:17:02Z

My solve was slightly different, possibly specific to something in my setup, but I ended up with the following

```
@development:
  ssh: $USER@lima-domain-com-au/srv/www/domain-com-au/current/
```

Note the dots in the domain are swapped for hyphens.

To figure that out I used the tip from @visualasparagus to check out `limactl show-ssh --format=config domain.com.au` which listed the host with hyphens.

`$USER` should mean it’s not specific to _my_ local and the others can use the same code, taken from [here](https://discourse.roots.io/t/tweaks-for-sync-script-with-trellis-and-lima/26715).

---

## Post 18 by @ben — 2025-01-23T05:33:26Z

I ran into this issue on a fresh macOS Sequoia install, and some of the workarounds mentioned in this topic _did_ work. But, there _is_ a way to get macOS and Lima to play together without that extra hassle.

I can confirm that just doing `ssh example.test` works on two of my macOS machines. My generated `wp-cli.trellis-alias.yml` file looks like:

```
"@development":
  ssh: "example.test"
  path: "/srv/www/example.com/current/web/wp"
```

Unfortunately, I don’t recall at which point/change I made that got things working for me. Maybe it was adding my SSH private key to macOS’s native keychain (which always bites me on a fresh install :sweat_smile:)?

```
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
```

[Reference](https://docs.github.com/en/enterprise-cloud@latest/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent)

---

## Post 19 by @bokorir — 2026-01-14T00:28:34Z

I ran into the same issue. It turned out to be an old entry in my `~/.ssh/config` related to the local development domain. Removing that stale configuration resolved the problem.
