滴水穿石

种一棵树最好的时间是十年前,其次是现在

0%

Visual Studio Code连接集群配置

在Windows上使用Visual Studio Code免密码登录集群/服务器。

安装插件

配置远程开发首先需要安装一个名为Remote - SSH的插件,具体操作步骤如下,

  • 点击扩展按钮
  • 搜索Remote - SSH 、Remote -WSL 和 vscode-icons
  • 安装

配置VSCode

step1: 点击VS code边栏的远程连接图标。

step2: 点击SSH TARGETS右边的齿轮状⚙️按钮。

step3: 在弹出来的C:\Users\XXX\.ssh\config文件中添加下面内容(即本地的C:\Users\user_name\.ssh\config),根据自己的用户名填写好各个字段,Ctrl + s保存。

1
2
3
4
5
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host gdl
HostName 192.168.106.31
User liaoshuilin
Port 22

step3: 参数设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Setting - Features - Terminal - Integrated > Automation Shell:Linux
{
"python.languageServer": "Microsoft",
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"remote.SSH.remotePlatform": {
"gdl": "linux"
},
"python.showStartPage": false,
"explorer.confirmDelete": false,
"window.zoomLevel": 0,
"terminal.integrated.automationShell.windows": "",
"workbench.iconTheme": "vscode-icons",
"workbench.colorTheme": "Default Dark+",
"workbench.editor.enablePreview": false,
"workbench.editor.enablePreviewFromQuickOpen": false,
"terminal.integrated.inheritEnv": false,
"terminal.integrated.automationShell.linux": ""
}

// Setting - Extension- Terminal - Remote - SSH,勾选✔ 以下项

1
2
3
4
5
Remote.SSH: Allow Local Server Download
Remote.SSH: Enable Agent Forwarding
Remote.SSH: Enable Dynamic Forwarding
Remote.SSH: Use Flock
Remote.SSH: Use Local Server

配置远程服务器免密码登录

这个需要windows配置有ssh工具,可以通过安装git、openssh实现。在本地打开cmd,

1
ssh-keygen # 获得本地客户端的公钥

然后一直点击Enter键,不用输入任何内容,最后会在C:\Users\user_name\.ssh路径下生成公钥文件,可以看到有一个id_rsa.pub文件,然后通过FTP等方式把这个文件上传到远程服务器。进入集群SSH配置目录,cd ~/.ssh,查看一下是否有一个名为authorized_keys的文件,如果没有就创建一个,然后把刚上传的id_rsa.pub中的内容附到authorized_keys文件中,并更改文件权限

1
2
3
touch authorized_keys
cat ~/id_rsa.pub >> authorized_keys
chmod -R 600 authorized_keys

删除 服务器中home目录下的 .vscode-server/目录后进行链接

1
rm -r  ~/.vscode-server/

参考链接

  1. VS Code远程开发
  2. Windows10系统下使用VS code远程连接集群(在有跳板机的情况下)
-------- 本文结束 感谢阅读 --------
# 添加内容