-
Notifications
You must be signed in to change notification settings - Fork 711
-
I was wondering if it is possible to use the ssh remote plugin for vs code with lima.
I think this is a great way to do development inside a vm in cases where this makes sense, IE working in a container does not provide the needed isolation or system access. In my case I was looking for a way to work with mininet without compromising my host system.
Here is what I found:
It works well with the following things to consider:
Make sure to have a ssh key on the machine (was missing in my case when I first tried)
Given this configuration
ssh:
localPort: 55555
loadDotSSHPubKeys: true
I can connect in vs code via the ssh remote plugin with the line myusername@localhost:55555
Setting a fixed local port is optional but I think it is more convenient than using randomly generated ports that need to be looked up.
(Previous post below, also works but is worse and more complicated, at this point I had not realized I was missing my own ssh key which required setting the ssh config file in vs code):
It seems to work this way, not sure if there is a more continent way:
- I've ran
limactl show-ssh --format=options my-vm
and copied the output to a file - I've configured that file in this option in vs code: Remote.SSH: Config File The absolute file path to a custom SSH config file.
- Now I've been able to connect via the ssh plugin with
myuser@localhost:$VMPORT
Without the custom ssh config file I get a public key denied error.
I have not used this yet but it looks promising. It would be nice if this could be made a bit more smooth.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 6 replies
-
There is now a ssh.config
generated for each instance, so can use that file instead of show-ssh
.
echo "Include ${LIMA_HOME:-$HOME/.lima}/default/ssh.config" >> ~/.ssh/config
Then you should be able to connect to "lima-default" (or any other instance), without parameters.
ssh lima-default
You can also add the ssh.config, from VS Code.
/home/anders/.lima/default/ssh.config
It should be available as a host, to connect to:
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 6
-
Awesome, I was not aware of this. This is better. Thanks for sharing 🚀
Is this something that is or should be documented? I'd be happy to contribute docs if that makes sense.
Beta Was this translation helpful? Give feedback.
All reactions
-
My idea was that it could go in the extended documentation, even if it's a bit outside the basic docs?
Not sure if it should be a book, or if it should be a part of https://lima-vm.io/
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
-
Another option would be to use VSCode tunnels, which will even work over another network with no dynamic DNS setup, port forwarding, etc.
Beta Was this translation helpful? Give feedback.
All reactions
-
I guess this is what you are referring to, right? Never noticed that before.
I'm not sure if it has any advantages in my use case, but good to know there are more options. Thanks for sharing.
Beta Was this translation helpful? Give feedback.
All reactions
-
The advantages are that you can access anywhere, even through vscode.dev, without having to worry about port forwarding and dynamic IP. My IPS for example blocks outside connections. I see you are complaining about containers as well because they do not offer isolation. You can use a remote devcontainer over the remote SSH inside the VM, which would be perfect. Unfortunately it does not work fos vscode.dev yet (you could help doing a +1 on my request microsoft/vscode-remote-release#9059)
Beta Was this translation helpful? Give feedback.
All reactions
-
Wanted to share my cozy dev setup on mac
in my .ssh/config:
Host lima-box
HostName 127.0.0.1
User lima-admin
Port 60022
IdentityFile ~/.lima/_config/user
StrictHostKeyChecking=no
UserKnownHostsFile=/dev/null
now i can jump into with
code --folder-uri vscode-remote://ssh-remote+lima-box/home/lima-admin
Beta Was this translation helpful? Give feedback.
All reactions
-
🚀 1
-
Thanks for sharing, I'll try that out
Beta Was this translation helpful? Give feedback.
All reactions
-
If you use the generated file, it will automatically reflect any changes in dynamic ports and add some optimizations as well.
You can of course duplicate it in your ~/.ssh/config like this, but you shouldn't have to... Maybe for adding another user etc.
Beta Was this translation helpful? Give feedback.