hymcr05 2024-05-26 21:22 采纳率: 0%
浏览 32

vscode如何实现局域网内的远程ssh?

vscode如何实现局域网内的远程ssh?
就是我有两台电脑,控制机是:windows 被控机是unbuntu 20.04
无公网ip
如果直接输入ip地址就会报错:

img


报错内容:

[21:20:04.175] Log Level: 2
[21:20:04.182] SSH Resolver called for "ssh-remote+192.168.1.28", attempt 1
[21:20:04.183] "remote.SSH.useLocalServer": false
[21:20:04.183] "remote.SSH.useExecServer": true
[21:20:04.183] "remote.SSH.showLoginTerminal": true
[21:20:04.184] "remote.SSH.remotePlatform": {"9.tcp.cpolar.top":"linux","192.168.1.28":"windows","5.tcp.vip.cpolar.cn":"linux"}
[21:20:04.184] "remote.SSH.path": undefined
[21:20:04.184] "remote.SSH.configFile": undefined
[21:20:04.184] "remote.SSH.useFlock": true
[21:20:04.184] "remote.SSH.lockfilesInTmp": false
[21:20:04.184] "remote.SSH.localServerDownload": auto
[21:20:04.184] "remote.SSH.remoteServerListenOnSocket": false
[21:20:04.185] "remote.SSH.showLoginTerminal": true
[21:20:04.185] "remote.SSH.defaultExtensions": []
[21:20:04.189] "remote.SSH.loglevel": 2
[21:20:04.189] "remote.SSH.enableDynamicForwarding": true
[21:20:04.189] "remote.SSH.enableRemoteCommand": false
[21:20:04.189] "remote.SSH.serverPickPortsFromRange": {}
[21:20:04.189] "remote.SSH.serverInstallPath": {}
[21:20:04.192] VS Code version: 1.89.1
[21:20:04.192] Remote-SSH version: remote-ssh@0.110.1
[21:20:04.192] win32 x64
[21:20:04.194] SSH Resolver called for host: 192.168.1.28
[21:20:04.194] Setting up SSH remote "192.168.1.28"
[21:20:04.198] Using commit id "dc96b837cf6bb4af9cd736aa3af08cf8279f7685" and quality "stable" for server
[21:20:04.200] Install and start server if needed
[21:20:04.204] Checking ssh with "D:\Program Files (x86)\VMware\VMware Workstation\bin\ssh.exe -V"
[21:20:04.207] Got error from ssh: spawn D:\Program Files (x86)\VMware\VMware Workstation\bin\ssh.exe ENOENT
[21:20:04.207] Checking ssh with "C:\Program Files\Microsoft\jdk-17.0.8.101-hotspot\bin\ssh.exe -V"
[21:20:04.209] Got error from ssh: spawn C:\Program Files\Microsoft\jdk-17.0.8.101-hotspot\bin\ssh.exe ENOENT
[21:20:04.209] Checking ssh with "C:\WINDOWS\system32\ssh.exe -V"
[21:20:04.211] Got error from ssh: spawn C:\WINDOWS\system32\ssh.exe ENOENT
[21:20:04.211] Checking ssh with "C:\WINDOWS\ssh.exe -V"
[21:20:04.213] Got error from ssh: spawn C:\WINDOWS\ssh.exe ENOENT
[21:20:04.213] Checking ssh with "C:\WINDOWS\System32\Wbem\ssh.exe -V"
[21:20:04.214] Got error from ssh: spawn C:\WINDOWS\System32\Wbem\ssh.exe ENOENT
[21:20:04.214] Checking ssh with "C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[21:20:04.215] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[21:20:04.215] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V"
[21:20:04.248] > OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2

[21:20:04.252] Remote command length: 4901/8192 characters
[21:20:04.252] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 62566 "192.168.1.28" powershell
[21:20:04.254] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[21:20:04.548] > ]0;C:\WINDOWS\System32\cmd.exe
[21:20:04.548] Got some output, clearing connection timeout
[21:20:04.563] > 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
[21:20:04.580] > @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
> @    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 ECDSA key sent by the remote host is
> SHA256:ma97GOuq3ExsB+OnkOzcZLKmAzEMNjl8LZgfnqRoZ0c.
> Please contact your system administrator.
> Add correct host key in C:\\Users\\user/.ssh/known_hosts to get rid of this message.
> Offending ECDSA key in C:\\Users\\user/.ssh/known_hosts:9
> ECDSA host key for 192.168.1.28 has changed and you have requested strict checking. 
> Host key verification failed.
[21:20:04.600] > 
> 过程试图写入的管道不存在。
[21:20:05.903] "install" terminal command done
[21:20:05.903] Install terminal quit with output: 过程试图写入的管道不存在。
[21:20:05.903] Received install output: 过程试图写入的管道不存在。
[21:20:05.904] Failed to parse remote port from server output
[21:20:05.905] Resolver error: Error: 
    at g.Create (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:499181)
    at t.handleInstallOutput (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:496503)
    at t.tryInstall (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:620043)
    at async c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:579901
    at async t.withShowDetailsEvent (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:583207)
    at async k (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:576866)
    at async t.resolve (c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:580578)
    at async c:\Users\user\.vscode\extensions\ms-vscode-remote.remote-ssh-0.110.1\out\extension.js:2:846687
[21:20:05.908] ------



  • 写回答

4条回答 默认 最新

  • 檀越@新空间 2024-05-26 21:23
    关注

    晚上好🌙🌙🌙
    本答案参考ChatGPT-3.5

    要解决这个问题,您可以尝试以下步骤:

    1. 检查您的~/.ssh/known_hosts文件中是否有错误的或不正确的证书信息。如果您确定您的服务器上有正确且完整的证书,则需要删除不需要的证书。

      可以使用ssh-keygen命令来生成一个新的公钥和私钥对,并将它们添加到known_hosts文件中:

      ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -q
      
    2. 如果您想确保所有必要的更改都已成功执行,并使系统能够通过SSH连接到远程服务器,可以运行以下命令检查您的SSH配置是否正常工作:

      ssh-keyscan 192.168.1.28 | grep server
      

      如果运行结果为server,则说明安装和配置过程已经完成。

      确保server是你想要连接到的远程服务器的IP地址。

    3. 如果问题仍然存在,可能是因为Windows系统中无法连接到Linux发行版的远程服务器。在这种情况下,您可能需要手动安装SSH服务。为此,请按照以下步骤操作:

      a. 打开命令提示符,然后输入以下命令安装SSH服务:

      netsh advfirewall firewall add rule name=" Allow remote access" dir=in action=allow protocol=tcp localport=22 comma-separated-list=<target-ip-or-port>
      

      其中 <target-ip-or-port> 是您想要允许的远程主机的IP地址或端口号。

      b. 接下来,打开~/.ssh/config文件,找到 Host <hostname> 的行,并将其替换为 Allow remote access 行中的目标 IP 地址或端口号。例如:

      Host <hostname>
          HostName <target-ip-or-port>
          Port 22
          IdentityFile ~/.ssh/id_rsa_server
      

      c. 最后,保存并关闭文件。

    4. 后续,您可以通过命令行输入 ssh 命令来连接到远程服务器。

    注意:这种方法可能不会立即解决问题,因为它涉及到重置某些配置项。因此,在执行此操作之前,建议先备份重要数据。

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 5月26日