引言:
VS Code可以支持Remote Development, 对于服务器上的开发比较友好,可以尝试使用
配置好之后就是下面这个样子的,注意右下脚,SSH:10.106.34.6 代表当前是在编辑远程的文件

Remote Development插件:
Remote Development - Visual Studio Marketplace
本地安装vscode
下载地址: Visual Studio Code - Code Editing. Redefined
Remote Development插件要求服务端的vscode和本地的vscode版本一致,所以安装之前先看一下远程vscode的版本, 如下图,远程服务器版本为1.40.1
schspa@sft-compile:~ /j-qemu |⇒ code --version 1.40.1 8795a9889db74563ddd43eb0a897a2384129a619 x64 |
安装Remote Development插件:
Launch VS Code Quick Open (Ctrl+P
), paste the following command, and press enter.
ext install ms-vscode-remote.vscode-remote-extensionpack |
安装并配置ssh:
下面是官方的guide
Visual Studio Code Remote Development Troubleshooting Tips and Tricks
使用git for windows就可以了。
安装完成之后,生成key,并且使用ssh-copy-id拷贝公钥到服务器上即可
Schspa-PC+Schspa@Schspa-PC MINGW64 ~ $ ssh -keygen.exe Generating public /private rsa key pair. Enter file in which to save the key ( /c/Users/Schspa/ . ssh /id_rsa ): Created directory '/c/Users/Schspa/.ssh' . Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /c/Users/Schspa/ . ssh /id_rsa . Your public key has been saved in /c/Users/Schspa/ . ssh /id_rsa .pub. The key fingerprint is: SHA256:1HuYSNoZuiybf3s3B8KaR6dTXWhtTJDv+3cK0qBQDDg Schspa-PC+Schspa@Schspa-PC The key's randomart image is: +---[RSA 3072]----+ | .. .o | | E o . . .| | . * . * | | B + + o *| | + S.= .o + | | . o .+++ . .| | . o .+.=o. .| | + + =.o...o| | o....+ o o..=| +----[SHA256]-----+ Schspa-PC+Schspa@Schspa-PC MINGW64 ~ $ ssh -copy- id schspa@10.106.34.6 /usr/bin/ssh-copy-id : INFO: Source of key(s) to be installed: "/c/Users/Schspa/.ssh/id_rsa.pub" The authenticity of host '10.106.34.6 (10.106.34.6)' can't be established. ECDSA key fingerprint is SHA256:OQiGUeaTGzWhTFc9L3RplywMevR /c8AfsC7hwqC8ha4 . Are you sure you want to continue connecting ( yes /no/ [fingerprint])? yes /usr/bin/ssh-copy-id : INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id : INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys schspa@10.106.34.6's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'schspa@10.106.34.6'" and check to make sure that only the key(s) you wanted were added. Schspa-PC+Schspa@Schspa-PC MINGW64 ~ $ |
连接远程服务器:
按照下图所示设置,添加服务器即可,连接之后,即可访问远程文件
基本就像在本地使用一样,但是要比vnc或者X11 Forwarding要快很多

选择远程服务器的操作系统类型:

如果不选择远程服务器的操作系统类型会弹出如下错误提示:

离线安装插件:
https://www.cnblogs.com/litaozijin/p/13202992.html
copy 进服务器的文件,可能权限不足。导致无法连接ssh。
chmod a+x commit_id/bin/code-server
chmod a+x commit_id/node
chmod a+x commit_id/server.sh+
chmod 755 commit_id/node_module/* -R
简单的方法是,在可联网的机器上搭建一个相同的环境,把工作机器 .vscode 文件夹 和 服务器 .vscode-server 文件夹,复制到对应的机器上。
官方文档:
Terminal Shell Integration in Visual Studio Code