VSCode远程开发 Windows11 Linux

问题背景

之前一直用JetBrains的Gateway和本地Linux虚拟机开发,不过笔记本配置不够,太卡了。最近租了个国外的便宜服务器,JetBrains的Gateway总断连,也不知道为什么,所以试试VSCode。

本地 Windows 11 ,远程 Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-25-generic x86_64)

2024-02-22 之前存的草稿没发布,不幸电脑安装了个Windows11测试版更新进不了桌面,重装后又装了一次。

解决过程

一般使用ssh连接的命令(需要另行输入密码):

shell 复制代码
ssh <User Name>@<IP Address>
ssh root@192.168.134.130

之前远程已经安装了go和ssh。

安装vscode-remote-extensionpack

安装ns(ncat,nc)

连接到服务器走代理可能速度快一些,需要用到nc。

我之前就安装了 Windows 包管理工具Chocolatey

2024-02-22 补充:安装 Chocolatey

使用管理员权限模式打开Powershell,执行以下命令,安装并检查是否安装成功:

bash 复制代码
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

choco -?

问一问 ChatGPT ,可知需要安装 nmap,其中包括ncatncatnc的一个增强的版本。顺便问后文所提的代理命令。

powershell 复制代码
choco install nmap

配置ssh

在本地配置ssh

对于一般的配置,可以通过输入使用的ssh命令添加远程。

对于较复杂的配置,可以通过编辑ssh配置文件~/.ssh/config~表示用户目录。

配置后内容如下:

复制代码
Host xxx
    HostName 127.x.x.x
    User root
    ForwardAgent yes
    IdentityFile ~/.ssh/id_ed25519
    ProxyCommand ncat --proxy localhost:7890 --proxy-type http %h %p
  • Host 是名字
  • HostName 是 IP 地址
  • User 是远程的用户名
  • ForwardAgent 大概是指是否支持远程机器使用本地密钥
  • IdentityFile 在本地生成的ssh私钥
  • ProxyCommand 代理命令

id_ed25519 生成参考:
Github: 生成新的 SSH 密钥并将其添加到 ssh-agent
在 Git for Windows 上自动启动 ssh-agent
测试 SSH 连接

注意:代理要配置为可以接受"局域网连接",也就是同一机器上程序的连接,大概是因为监听localhost

在远程配置ssh

把 IdentityFile 对应的公钥发送到远程,配置远程ssh支持通过此公钥登录。

修改 ssh 配置 /etc/ssh/sshd_config

(我的机器初始时以下前两行是注释掉的,后一行没有,不确定实际需不需要后一个)

复制代码
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

RSAAuthentication yes

.ssh/authorized_keys中加入公钥的内容,无需执行重启等其它操作。

SSH timed out

因为总是连接错误,提示:
Could not establish connection to "xxx": Connecting with SSH timed out.

VSCode Setting设置中配置(我直接都设了,没注意是哪个起了作用):

  • remote.SSH.useLocalServer : true
  • remote.SSH.remotePlatform : {"Host": "linux"}

Host为ssh配置中的Host。

后续步骤

后续按提示安装 VSCode Golang 需要的工具。

尚存的问题

构建的时候

参考资料

ChatGPT: 配置VS Code远程代理

【Linux】配置SSH免密登录
使用Linux,从正确配置ssh开始
vscode+go远程开发
VScode连接linux服务器timed out Could not establish connection \* SSH timed out 解决方案集合,总有一个能成功
vscode和虚拟机联网的一些问题备注
windows平台VS code配置remote ssh

Github: Connecting to GitHub with SSH
Github: Troubleshooting SSH
Gitee: SSH 公钥设置

相关推荐
orion571 天前
Missing Semester Class1:course overview and introduction of shell
linux
用户120487221611 天前
Linux驱动编译与加载
linux·嵌入式
用户805533698031 天前
Input 子系统架构:Core、Handler、Driver 三层是怎么协作的
linux·嵌入式
用户805533698031 天前
RK-Forge外设系列开篇 - 把板子从「能启动」变成「能用」:Ethernet/SPI/MMC 三个纯接线外设
linux·github·嵌入式
七歌杜金房2 天前
我终于又有了自己的 Linux 电脑
linux·debian·mac
tntxia3 天前
linux curl命令详解_curl详解
linux
扛枪的书生3 天前
Linux 网络管理器用法速查
linux
顺风尿一寸3 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode3 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫4 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux