恒源云 _ 云 GPU 服务器如何使用 VSCode?

文章来源 | 恒源云社区(专注人工智能/深度学习云 GPU 服务器训练平台,十一月宠粉活动 ing,官方体验网址:https://gpushare.com/ )
原文地址 | https://gpushare.com/docs/best_practices/vscode/
VSCode
VSCode 是微软开发的一款跨平台代码编辑器,免费、开源并且支持扩展插件。使用 Remote 插件可以连接到远程服务器上进行开发。
安装扩展
侧边栏点击 扩展 标签,搜索 Remote - SSH 插件点击安装。如果需要使用中文界面,再安装 Chinese (Simplified) 插件,重启后可显示中文。

添加远程主机
安装扩展后在侧边栏点击 远程资源管理器 标签,点击加号按钮添加远程主机。

在 我的实例 中点击复制登陆指令。

将复制的登陆指令粘贴,输入 「Enter」。

远程主机信息会保存在本地配置文件中,选择第 1 个配置文件完成添加。

连接远程主机
添加完成后在 远程资源管理器 中显示刚添加的远程主机。点击在新窗口中打开连接的按钮。

在新弹出的窗口中选择 Linux 系统。

提示主机密钥指纹,选择 Continue。

在 我的实例 中点击复制登陆密码。

将复制的登陆密码粘贴,输入 「Enter」。

成功连接后点击 资源管理器 标签会显示已连接到远程。同时左下角提示已连接的远程主机名称。

🔥提示
如果连接提示“试图写入的管道不存在”,可能是 Windows 自带的 SSH 问题。可以通过安装 Git,然后在 VSCode 首选项 - 设置中搜索
remote.SSH.path
,填写C:\Program Files\Git\usr\bin\ssh.exe
让 VSCode 使用 Git 提供的 SSH 客户端。
使用远程主机
点击左下角的问题图标,再点击 终端 标签。打开的终端自动登录到远程服务器。使用 mkdir example
创建一个文件夹用于编写代码。

点击打开 打开文件夹,选择刚刚创建的 example
文件夹,点击确定。

打开后资源管理器中显示的是远程主机的文件,可以在当前工作区创建编辑代码。

在终端窗口中执行命令运行代码。

当使用完成需要退出时,点击左下角蓝色 SSH 主机名。选择 关闭远程连接。

VSCode 官方文档:Remote Development using SSH
评论