问题描述
我正在研究一些教程并尝试做一些事情,但是不知道是否可以完成.我正在Windows 10中使用Windows终端.我正在运行Ubuntu虚拟机.
I'm working on some tutorials and trying to do something, but no idea if it can be done. I am using windows terminal in Windows 10. I have an Ubuntu virtual machine running.
我想:
- 打开Windows终端
- SSH进入Linux虚拟机
- 键入
code
命令,并使其在我的Windows PC上打开VS Code的版本,该版本在Ubuntu VM中的文件夹上运行.
- Open Windows terminal
- SSH into the Linux Virtual Machine
- Type in the
code .
command and have it open a version of VS Code on my Windows PC that is working on the folder in the Ubuntu VM.
我尝试在另一台计算机上的本地和命令行上安装代码,但是它不起作用.我确信还有其他方法可以做到这一点,但我想解释一下我是如何做的,以表明我至少尝试过一些东西.感谢您的帮助.
I tried install code locally and on the command line in the other machine, but it doesn't work. I am sure there are other ways to do this but wanted to explain how I was doing it to show I at least tried something. Thanks for your help.
推荐答案
它不如您通过 Remote-WSL 扩展名获得的 code
技术那么简单,但是Microsoft还提供了 Remote-SSH 扩展名,可用于直接访问远程计算机(不需要中间的WSL).
It's not quite as easy as the code .
technique you get with the Remote - WSL extension, but Microsoft also provides a Remote - SSH extension that can be used to directly access the remote machine (without requiring WSL in-the-middle).
在VSCode中安装了 Remote-SSH 扩展名之后(它可能已经安装在带有WSL扩展名的扩展包中),并且在Windows中安装了OpenSSH客户端,通过SSH访问远程主机上文件的几种方法:
Once the Remote - SSH extension is installed in VSCode (and it may have already been installed in an extension pack with the WSL extension), and you have installed an OpenSSH client in Windows, there are several ways to access files on the remote host through SSH:
-
从命令面板( + + )中,键入Remote SSH以筛选这些命令.从连接到主机,您可以添加新配置,等等.
From the Command Palette (++), type Remote SSH to filter on those commands. From Connect to Host, you can add a new configuration, etc.
从左侧的活动栏中,选择 Remote Explorer 图标,然后在顶部的下拉列表中,选择 SSH Targets .您可以通过+图标在此处添加主机.
From the Activity Bar on the left, select the Remote Explorer icon, then in the dropdown at the top, select SSH Targets. You can add hosts here through the + icon.
在状态栏的最左侧有一个直接的打开远程窗口快捷键.这将为您在命令面板"上提供与上述类似的过滤器选项.
There's a direct shortcut to Open a Remote Window at the far left of the status bar. This will give you similar filter options on the Command Palette as above.
一旦配置了主机,就可以浏览(就像,几乎是)主机一样(如果是本地主机),打开文件,进行编辑等.就我所知,无法做的一件事是在您没有直接权限的文件上进行任何类型的 sudo
/ su
编辑.
Once a host is configured, you can browse it just as (well, almost) if it were local, open files, edit, etc. The one thing you can't do (as far as I'm aware) is any type of sudo
/su
editing on files that you don't have permissions to directly.
VSCode文档中的完整详细信息此处.
Full details in the VSCode docs here.
这篇关于通过SSH进入虚拟机时,是否可以从Windows终端打开VSCode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!