报错
使用vscode的Remote - SSH插件远程连接不同服务器时报错如下
bash
[11:42:51.784] Log Level: 2
[11:42:51.792] SSH Resolver called for "ssh-remote+27.23.24.103", attempt 1
[11:42:51.793] "remote.SSH.useLocalServer": false
[11:42:51.793] "remote.SSH.useExecServer": true
[11:42:51.793] "remote.SSH.showLoginTerminal": false
[11:42:51.794] "remote.SSH.remotePlatform": {"ubt01":"linux"}
[11:42:51.794] "remote.SSH.path": undefined
[11:42:51.794] "remote.SSH.configFile": undefined
[11:42:51.794] "remote.SSH.useFlock": true
[11:42:51.794] "remote.SSH.lockfilesInTmp": false
[11:42:51.796] "remote.SSH.localServerDownload": auto
[11:42:51.797] "remote.SSH.remoteServerListenOnSocket": false
[11:42:51.797] "remote.SSH.showLoginTerminal": false
[11:42:51.797] "remote.SSH.defaultExtensions": []
[11:42:51.797] "remote.SSH.loglevel": 2
[11:42:51.797] "remote.SSH.enableDynamicForwarding": true
[11:42:51.797] "remote.SSH.enableRemoteCommand": false
[11:42:51.797] "remote.SSH.serverPickPortsFromRange": {}
[11:42:51.797] "remote.SSH.serverInstallPath": {}
[11:42:51.801] VS Code version: 1.88.1
[11:42:51.801] Remote-SSH version: remote-ssh@0.110.1
[11:42:51.801] win32 x64
[11:42:51.805] SSH Resolver called for host: 27.23.24.103
[11:42:51.805] Setting up SSH remote "27.23.24.103"
[11:42:51.809] Using commit id "e170252f762678dec6ca2cc69aba1570769a5d39" and quality "stable" for server
[11:42:51.814] Install and start server if needed
[11:42:53.512] Checking ssh with "C:\Windows\system32\ssh.exe -V"
[11:42:53.515] Got error from ssh: spawn C:\Windows\system32\ssh.exe ENOENT
[11:42:53.515] Checking ssh with "C:\Windows\ssh.exe -V"
[11:42:53.516] Got error from ssh: spawn C:\Windows\ssh.exe ENOENT
[11:42:53.516] Checking ssh with "C:\Windows\System32\Wbem\ssh.exe -V"
[11:42:53.518] Got error from ssh: spawn C:\Windows\System32\Wbem\ssh.exe ENOENT
[11:42:53.518] Checking ssh with "C:\Windows\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[11:42:53.519] Got error from ssh: spawn C:\Windows\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[11:42:53.519] Checking ssh with "C:\Windows\System32\OpenSSH\ssh.exe -V"
[11:42:53.575] > OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
[11:42:53.582] Running script with connection command: "C:\Windows\System32\OpenSSH\ssh.exe" -T -D 60388 "27.23.24.103" bash
[11:42:53.585] Terminal shell path: C:\Windows\System32\cmd.exe
[11:42:54.954] > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> ]0;C:\Windows\System32\cmd.exe
[11:42:54.955] Got some output, clearing connection timeout
[11:42:54.970] > @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
> @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
> Someone could be eavesdropping on you right now (man-in-the-middle attack)!
> It is also possible that a host key has just been changed.
> The fingerprint for the RSA key sent by the remote host is
> SHA256:g9XWs/eWk6STHGxpFzaEQQCPAeXtPn5+NhcXDu3vfwc.
> Please contact your system administrator.
> Add correct host key in C:\\Users\\Administrator/.ssh/known_hosts to get rid of
> this message.
> Offending RSA key in C:\\Users\\Administrator/.ssh/known_hosts:7
> RSA host key for 27.23.24.103 has changed and you have requested strict checking
> .
> Host key verification failed.
> 过程试图写入的管道不存在。
>
[11:42:56.262] "install" terminal command done
[11:42:56.263] Install terminal quit with output: 过程试图写入的管道不存在。
[11:42:56.263] Received install output: 过程试图写入的管道不存在。
[11:42:56.264] Failed to parse remote port from server output
[11:42:56.265] Resolver error: Error:
at g.Create (c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:499181)
at t.handleInstallOutput (c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:496503)
at t.tryInstall (c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:620043)
at async c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:579901
at async t.withShowDetailsEvent (c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:583207)
at async k (c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:576866)
at async t.resolve (c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:580578)
at async c:\Users\Administrator\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:846687
[11:42:56.273] ------
[11:42:56.657] Opening exec server for ssh-remote+27.23.24.103
[11:42:56.671] Initizing new exec server for ssh-remote+27.23.24.103
[11:42:56.704] Using commit id "e170253463534545RYF3456RG69aba1570769a5d39" and quality "stable" for server
[11:42:56.706] Install and start server if needed
[11:43:06.409] getPlatformForHost was canceled
[11:43:06.410] Exec server for ssh-remote+27.23.24.103 failed: Error: Connecting was canceled
[11:43:06.411] Error opening exec server for ssh-remote+27.23.24.103: Error: Connecting was canceled
原因
SSH主机密钥验证失败而未能成功建立连接。预期服务器的SSH密钥会发生变化,或者你更换了服务器,就需要更新本地的`known_hosts`文件。
解决
以下是日志中的一些关键信息和可能的解决方案:
关键信息:
-
**SSH Resolver调用**:Remote - SSH扩展尝试连接到IP地址`27.23.24.103`。
-
**SSH客户端路径**:VSCode找到了`C:\Windows\System32\OpenSSH\ssh.exe`作为SSH客户端。
-
**SSH连接命令**:使用了以下命令尝试建立SSH连接:
```
"C:\Windows\System32\OpenSSH\ssh.exe" -T -D 60388 "27.23.24.103" bash
```
-
**主机密钥变更警告**:VSCode提示远程主机的RSA密钥发生了变化,这通常意味着本地的`known_hosts`文件中的密钥与远程主机当前的密钥不匹配。
-
**连接失败**:由于主机密钥验证失败,SSH连接尝试失败。
-
**取消连接**:在尝试安装和启动服务器时,连接被取消。
可能的解决方案:
-
**检查SSH密钥**:如果你预期服务器的SSH密钥会发生变化,或者你更换了服务器,你需要更新本地的`known_hosts`文件。
-
**更新`known_hosts`**:你可以通过以下方式更新或删除本地的密钥记录:
-
手动打开`C:\Users\Administrator\.ssh\known_hosts`文件,找到对应的主机条目并删除。
-
或者,使用SSH命令连接时,使用`-o StrictHostKeyChecking=no`参数来跳过密钥检查(这会降低安全性,因为它容易受到中间人攻击)。
-
**确保SSH客户端正确安装**:确保`ssh.exe`位于指定路径,并且可以正常工作。
-
**检查网络连接**:确保你的网络连接可以到达远程服务器的IP地址,并且没有防火墙或路由器设置阻止了SSH连接。
-
**检查服务器状态**:确认远程服务器已经启动并且SSH服务正在运行。
-
**检查SSH配置**:确认VSCode的SSH配置没有错误,包括用户名、端口以及任何需要的密钥或密码。
-
**查看详细日志**:如果问题仍然存在,你可以通过增加Remote - SSH扩展的日志级别来获取更详细的信息,以便进一步调试。
-
**联系系统管理员**:如果你不确定如何处理SSH密钥更改的问题,联系服务器的系统管理员获取帮助。
注意
跳过主机密钥检查会降低安全性,因此只在你信任网络环境和远程主机时才使用。在生产环境中,始终确保使用最新的密钥,并且不要跳过密钥检查。