环境说明:
- Windows端:OS是Win10,IP:192.168.0.51,安装Windows版的VSCode,作为VS Client
- Linux端:OS是Ubuntu18.04,IP:192.168.0.6,安装C/C++开发必要的工具,如GCC,GDB等
安装步骤:
第一步:在Windows端VS Code中安装Remote Development插件
安装完成后如下:
image.png
第二步:建立不需要密码输入的SSH连接
这一步需要建立Windows端与Linux端之间的SSH连接,并且不需要输入密码。
- 在Windows端执行以下命令,生成SSH公钥:
C:\Users\sprin>ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\sprin/.ssh/id_rsa):
C:\Users\sprin/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\sprin/.ssh/id_rsa.
Your public key has been saved in C:\Users\sprin/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vnCS5UTQnKS5icSlUmUhWtgK8PnQF24X26XT5/Tdibo sprin@DESKTOP-OU95CS4
The key's randomart image is:
+---[RSA 2048]----+
|o o+.B=o. . |
|...B.* =++ + |
| .*.= * + + . o |
| .= + = . +..+|
| o o S ...+|
| * . |
| + + . |
| + . . |
| . E |
+----[SHA256]-----+
- 拷贝SSH公钥至Linux端:
C:\Users\sprin\.ssh>scp id_rsa.pub hank@192.168.0.6:/home/hank/.ssh
hank@192.168.0.6's password:
id_rsa.pub 100% 404 72.7KB/s 00:00
- 在Linux端执行,在/home/hank/.ssh/目录下:
#mv id_rsa.pub authorized_keys
#chmod 600 authorized_keys
第三步:在Windows端VS Code上使用Remote Development插件进行连接
点击“+”号,在命令行中输入“ssh hank@192.168.0.6”
image.png
右键点击在此窗口中连接
image.png
连接成功后,这台机器前面就变成一个绿色的勾,如上图。
第四步:在VS Code上安装Linux端C/C++ VS插件
image.png第五步:连接Linux端目录,创建开发编译环境
image.png创建一个测试文件:
image.png
选择“C++(GDB/LLDB)”
image.png选择“g++ Build and debug active file”
image.png
系统自动产生两个JSON文件,如下:
image.png
按“F5”,编译测试运行:
image.png
网友评论