Vscode通过SSH连接不上远程服务器,但是git bash中可以访问

问题描述:

我的window10 的版本是1709,通过在:
Vscode通过SSH连接不上远程服务器,但是git bash中可以访问_第1张图片
这里下载的OpenSSH可能是版本不对,在生成rsa秘钥的时候提示下面的:

PS C:\Program Files\OpenSSH-Win64> ssh-keygen -t rsa -b 4096
unknown key type rsa

但是在gitbash中却可以,也成功访问了服务器。
接着在vscode中访问却提示:

Could not establish connection to "XXX"

一直摸不到头绪,我尝试增加config的搜寻路径:
Vscode通过SSH连接不上远程服务器,但是git bash中可以访问_第2张图片
但是问题还是没有得到解决。

于是追溯到问题的一开始:怀疑是OpenSSH下载的问题,因为之前在1809的win10系统中dos窗口是可以生成rsa秘钥和公钥的,但是现在重装系统后的win10是1709,通过ssh-keygen 生成的j竟然是:

Generating public/private ed25519 key pair.

问题解决

1.在github中下载zip压缩包:

https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.1.0.0p1-Beta/OpenSSH-Win64.zip

2.解压到你想解压的目录后,将文件夹路径添加到Path:
Vscode通过SSH连接不上远程服务器,但是git bash中可以访问_第3张图片
3.进入到解压后的目录下,按住shift+鼠标右键进入powershell,运行:

PS C:\Program Files\OpenSSH-Win64> .\ssh-keygen.exe -t rsa -b 4096

如果这里失败了就执行:

PS C:\Program Files\OpenSSH-Win64> .\ssh-keygen.exe -A

之后会提示:

ssh-keygen: generating new host keys: RSA DSA ECDSA ED25519

4.然后再执行:

PS C:\Program Files\OpenSSH-Win64> .\ssh-keygen.exe -t rsa -b 4096

5.接着:

Generating public/private rsa key pair.
Enter file in which to save the key (C:\Users\Administrator/.ssh/id_rsa):
Created directory 'C:\Users\Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\Users\Administrator/.ssh/id_rsa.
Your public key has been saved in C:\Users\Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:lSAnlGzqSKMIMMJJQCR5D1nTGGF1aZ16Qj4IwB8diZM zpfighting@BUAA-ZP
The key's randomart image is:
+---[RSA 4096]----+
|O*o+*%*++o .     |
|*o=.E.B=+.o.     |
|oo + * = .o      |
|. o + . =..      |
|oo +    S+       |
|o . .            |
|                 |
|                 |
|                 |
+----[SHA256]-----+

之后就可以通过vscode添加SSH访问地址了:
Vscode通过SSH连接不上远程服务器,但是git bash中可以访问_第4张图片

你可能感兴趣的:(Vscode通过SSH连接不上远程服务器,但是git bash中可以访问)