Sync script & SSH access with Lima

Hey ya’ll… I found this:

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?

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

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.

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?

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.

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

trellis vm shell immediately connects:

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

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.

2 Likes

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

1 Like

It worked without supplying a user?

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

1 Like

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!

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.

1 Like

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

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"

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.

1 Like

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.

1 Like

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