您的位置 首页 golang

玩转VSC远程开发之Remote-SSH远程连接开发环境

昨天文章,我们介绍了VSC的远程开发扩展,包括了docker、SSH和WSL,本文虫虫来给大家实例深入介绍下 remote -SSH扩展。

之前的文章中我们说了远程开发扩展需要在最新的VSC Insiders版本,本文中我们提到的所有VSC都是在该版本下操作,截止本文撰写时候VSC Insiders最新版本为1.33。

概述

VSC的Remote-SSH扩展是VSC 远程开发的三个自插件之一,用于通过SSH协议 链接 到远程的 开发环境 ,打开远程文件夹,实现和VSC IDE功能的无缝集成。连接到服务器后,可以实现与远程服务器文件系统上的代码文件和运行环境交互。通过该扩展VSC实现在远程服务器运行命令和扩展,本地VSC所在计算机上无需要源代码和开发运行环境,就能实现和提供本地开发一样的体验,包括完整的IntelliSense(高亮、补全),代码导航和断点调试等。

玩转VSC远程开发之Remote-SSH远程连接开发环境

安装部署

Remote-SSH依赖于一下软件,要使用该插件必须安装首先安装:

安装依赖插件

VSC Insiders尝鲜版 :即绿色头标的VSC。VSC真实版本是蓝色头标的。

兼容OpenSSH的 SSH客户端 :需要配置Windows路径,不支持Putty。

具体安装步骤:

MS+X 启动管理员身份启动的命令行,输入 PowerShell 进到Powershell界面。

输入以下PowerShell命令获取在线的Openssh

Get-WindowsCapability -Online | ? Name -like ‘OpenSSH*’

通过输入命令安装OpenSSH客户端

Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

玩转VSC远程开发之Remote-SSH远程连接开发环境

安装远程开发 Remote Development 扩展包。

SSH客户端配置

如果服务器需要通过多因素身份验证,比如要用证书登陆,需要设置

settings.json的remote.SSH.showLoginTerminal:true启用ControlMaster SSH功能。

玩转VSC远程开发之Remote-SSH远程连接开发环境

VSC使用SSH配置文件,并且需要基于SSH密钥认证才能连接到主机。具体配置方法如下:

1、 配置公钥认证,并在远程主机上(本例中的10.0.1.8)添加公钥到~/.ssh/authorized_keys

2、 在VSC命令选项板(或者F1)选择Remote-SSH:Connect to Host,下拉列表选择 config ure SSH Hosts …,配置远程服务器信息:HostName,Port,User以及私钥的文件(和添加到远程服务器的公钥配对)。

玩转VSC远程开发之Remote-SSH远程连接开发环境

注意设置~/.ssh/目录下config和证书的文件权限,需要配置给当前用户, Administrators 和 YSTEM全部控制权限。

2、运行VSC命令选项板(或者F1)Remote-SSH:Connect to Host,选择主机比如我们上一步奏配置的SEC-test,或者自定义输入主机名和用户(注意这种情况主机的端口必须为默认的22),格式为:user@hostname

玩转VSC远程开发之Remote-SSH远程连接开发环境

3、VSC会连接到SSH服务器并自行设置。 VSC将使用进度条提示连接的信息,可以在Remote-SSH 输出标签页中查看详细日志。

4.连接后,将进入一个空窗口。我使用可以使用文件>打开,或文件>打开工作区打开远程服务器上的文件文件夹或工作区

玩转VSC远程开发之Remote-SSH远程连接开发环境

5.选择的文件夹或工作区将会打开。从”扩展”视图中安装需要的扩展,比如Python扩展。

玩转VSC远程开发之Remote-SSH远程连接开发环境

记住常连主机

配置过程和上步骤中第二步骤,在配置文件中重复建立不同的Host配置项即可,比如我们再增加一个数据主机:

玩转VSC远程开发之Remote-SSH远程连接开发环境

保存,再此连接时候就能看到保存这个主机SEC-db了。

玩转VSC远程开发之Remote-SSH远程连接开发环境

如果要使用与列出的配置文件不同的配置文件,需要在settings.json中设置”remote.SSH.configFile”属性。

管理扩展

VSC扩展运行在UI/客户端本地,或在远程主机上。影响VSC UI的扩展(如主题和代码段)都安装在本地,但大多数扩展要都要运行在远程主机上。这可确保获得流畅的体验,需要通过为SSH主机上的给定工作区安装任何所需的扩展。

如果从”扩展”视图安装扩展,它将自动安装在正确的位置。安装后,可以根据类别分组确定扩展的安装位置。远程SSH主机和本地安装类别将有一个类别。

比如下面就是一个远程扩展:

玩转VSC远程开发之Remote-SSH远程连接开发环境

默认安装扩展程序

如果希望在连接的SSH主机上是默认安装远程扩展,可以配置settings.json remote.SSH.extensions属性指定需要安装的扩展。例如,如果要安装GitLens和资源监视器扩展,请按如下所示指定其扩展ID:

玩转VSC远程开发之Remote-SSH远程连接开发环境

强制扩展在本地或者远程运行

扩有时候由于测试或者其他需要,要让扩展只运行在本地或者远程主机上,而无需两方都运行。基于扩展程序的选项,可在settings.json设置其运行在本地或者远程主机。

例如,下面的设置将强制Docker和Debugger for Chrome扩展程序远程运行而不是本地默认值:

玩转VSC远程开发之Remote-SSH远程连接开发环境

上面配置的中的workspace表示扩展运行在远程主机,对应一个值”ui”则表示将其在本地UI/客户端上运行。

端口转发 和SSH隧道

Remote-SSH插件也支持Openssh特有一些高级功能,比如SSH转发和SSH隧道。

临时端口转发

如果要在会话期间临时转发新端口,可以在连接到SSH主机时候运行ssh转发,格式为: Remote-SSH: Forward Port from Active Host

输入端口号后,会通知使用本地主机端口来访问远程端口。例如,如果转发监听的端口3000的HTTP服务器,则通知可能会告诉它已映射到 localhost 上的端口4123。

此时就可以通过localhost:4123访问远程的HTTP服务

固定端口转发

如果需要设定一个可以长期使用的端口转发提供服务,则需要在.ssh/config中配置转发的配置,则可以在上面的”记住常连主机”部分配置类似,不过增加i个LocalForward指令即可。

例如,如果要转发端口8080和6379,可按照下面配置:

玩转VSC远程开发之Remote-SSH远程连接开发环境

上面配置中,我们把两个远程服务器上端口8080和6379转发到本机8888和6666,这样就可以在本地通过ssh隧道访问远程服务器上的web和redis服务了。

远程主机终端

从VSC打开远程主机上的终端很简单。连接后,在VSC菜单中的( Terminal > New Terminal )中打开的任何终端窗口,就会自动连接到远程主机上,并可执行shell操作。

还可以使用此同一终端窗口中的code-insiders命令行来执行许多操作,例如在远程主机上打开新文件或文件夹。

玩转VSC远程开发之Remote-SSH远程连接开发环境

远程代码调试

连接到远程主机后,可以像在本地运行应用程序一样使用VSC的调试器。例如,如果在launch.json中选择启动配置并开始调试(F5),则应用程序将在远程主机上启动并对其使用调试器。

玩转VSC远程开发之Remote-SSH远程连接开发环境

限制和缺点

Remote-SSH插件虽然提供强大的远程开发支持,但是目前预览版本还存在很多的限制。

为安全方便建议使用证书方式进行认证,虽然也支持基于账号密码和token认证凭据不能保存。

目前还不支持不支持Windows和 macOS 的远程主机。(支持Windows和macOS客户端。)

Windowss

Linux主机必须安装Bash,tar和curl或wget。

Windows的SSH客户端不支持PuTTY,而且.ssh文件权限配置较复杂,配置给当前用户,Administrators和 YSTEM全部控制权限。

无法在文件资源管理器中将文件直接复制到本地。

连接到SSH主机时安装扩展包时,扩展可以在本地安装,而不是在主机内部安装。

如果使用SSH clone 存储库且SSH密钥设置了密码时候,远程运行时,VSC的拉取和同步功能可能会挂起。

远程主机上不会重复使用本地代理设置,这可能会阻止扩展工作,需要在远程主机上配置合适的代理信息(例如,配置全局的HTTP_PROXY或HTTPS_PROXY环境变量)。

总结

Remote-SSH做为VSC最新远程开发插件中的主打功能,我们本文实例介绍其安装、配置、使用和高级配置的一些方法。大家可以对比文章内容动手操作玩玩,学以致用,只有动手才能真正的掌握一门技术。

文章来源:智云一二三科技

文章标题:玩转VSC远程开发之Remote-SSH远程连接开发环境

文章地址:https://www.zhihuclub.com/98509.shtml

关于作者: 智云科技

热门文章

评论已关闭

35条评论

  1. For example, food allergies and allergies to medications do not typically cause allergic rhinitis However, there is a potential for Cialis to follow the OTC-approval pattern of Viagra

  2. Drugs for Erectile Dysfunction and Premature Ejaculation in Trinidad and Tobago When purchasing FDA approved medications from our internet pharmacy, you can pay with MasterCard, Bitcoin or Visa

  3. Monitor blood pressure response to phosphodiesterase type 5 PDE5 inhibitors in patients receiving concurrent blood pressure lowering therapy

  4. azithromycin given as two or four tablets at once doxycycline given as two capsules a day for a week.

  5. In independent validation data Nurses Health Study cohort the breast and ovarian cancer models were well calibrated; expected to observed cancer ratios were 1 This implies that the CD44 CD24 low tumor propagating cell population may have undergone EMT, and that this process is, in part, mediated by TGF ОІ

  6. com 20 E2 AD 90 20Viagra 20100 20Mg 20Tablet 20 20Penegra 20100mg 20Vs 20Viagra penegra 100mg vs viagra The 38 year old late night TV host was spotted exiting his New York City apartment on Thursday with his arms full

  7. Monitor Closely 1 fluvoxamine will increase the level or effect of guanfacine by affecting hepatic intestinal enzyme CYP3A4 metabolism

  8. While the majority of human L1s are inactive, 80 100 elements remain retrotransposition competent and mobilize through RNA intermediates to different locations within the genome

  9. Studies supporting benefits of a moderate level of soy foods should not be used to support use of isolated soy protein or isoflavones, especially in amounts beyond what can be reached with diet PMID 25326582 Review

  10. The Channel 4 newsreader sent viewers an email on Thursday with the headline Has David Miliband been tough enough on Syria He added We will also be debating Ed Miliband s leadership of the Labour Party

  11. Another IBS drug, Lotronex alosetron, was approved for diarrhea predominant IBS in February 2000; it was withdrawn before the end of that year because it was linked to ischemic colitis Comparisons were also made of clinical response with ultrasound response, actual and feasible surgery with feasible surgery at baseline, OR in human epidermal growth factor receptor 2 HER2 positive cancers, and tolerability

  12. A number of pathways that include both pro and anti inflammatory ones were examined, including those mediated via cytokine signaling and several that are linked to autoimmune responses

  13. Chitosan can be added to the PEG AM PEG NHS hydrogels for impartation of a positive charge to the hydrogel, for the purpose of sequestration of the hydrogel to the skin

  14. 5 of every 100 intensive care unit admissions and 4 of 10 admissions associated with an aminotransferase level 10 times the upper limit of normal

  15. While the diagnosis is clinical in most cases, sometimes a biopsy may be required to rule out another disorder

  16. Design Cross sectional descriptive study If you experience dizziness or lightheadedness, see your physician to rule out any underlying medical problems and to check your medications

  17. Toxicity of tamoxifen Tamoxifen was initially considered an antiestrogen in breast tissue, acting through competitive inhibition of estrogen binding to the ER

  18. The prevalence of depression in women with polycystic ovary syndrome PCOS is high; one study has shown it to be four times that of women without PCOS Approximately 47 percent of all infertile couples will have a male infertility component

  19. He is eyesight improve with blood pressure medication 2 meters tall, looks to be in his early 50s, his face is full of traces of wind and frost, and his bushy beard has turned white Therefore, the initial weight lost when someone dramatically reduces carbohydrate intake is really just water weight, and not actual fat

  20. myofascial pain or multifidus muscle atrophy, and intraabdominal retroperitoneal pathology i I just dread it tho when I have to say I m out of Poise because of the expense and just IT

  21. For chronic AUB, any form of monophasic, triphasic, extended, or continuous monophasic COC may be used

  22. Aguilar C, Cornell J, et al com Registrant Direct Privac y ID 258EA PO Box 12068 George Town, Grand Cayman KY1 1010 KY 1 345 745 6022

网站地图