Windows

windows上的openssh設置:連接重置

  • October 16, 2020

我在我的 Windows 機器(Windows 10 Enterprise Edition OS)上使用 Hyper-V 設置了一個(Ubuntu)虛擬機,但似乎我的學校網路安全規則不允許我將網際網路共享到 VM,所以我想設置建立一個 ssh 隧道(允許在虛擬機上訪問網際網路,以便使用 輕鬆安裝包apt install)。

我在 windows 機器上安裝了 OpenSSH-Win64。但是當我嘗試從 ubuntu VM 連接時,它給了我錯誤:

miranda@ubuntu-vm:~$ ssh -v 'cecs-030929\admin-u5214628'@150.203.213.249
OpenSSH_7.2p2 Ubuntu-4ubuntu2.2, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 150.203.213.249 [150.203.213.249] port 22.
debug1: Connection established.
debug1: identity file /home/miranda/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miranda/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6
debug1: match: OpenSSH_7.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 150.203.213.249:22 as 'cecs-030929\\admin-u5214628'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
Connection reset by 150.203.213.249 port 22

我不知道在哪裡看。一些來自 Ubuntu VM 的檢查:

miranda@ubuntu-vm:~$ tcpdchk
miranda@ubuntu-vm:~$ tcpdchk -v
Using network configuration file: (null)
miranda@ubuntu-vm:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:15:5d:d5:f9:07
         inet addr:150.203.213.248  Bcast:150.203.213.255  Mask:255.255.255.0
         inet6 addr: fe80::215:5dff:fed5:f907/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:104320 errors:0 dropped:0 overruns:0 frame:0
         TX packets:369 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:16960579 (16.9 MB)  TX bytes:65010 (65.0 KB)

lo        Link encap:Local Loopback
         inet addr:127.0.0.1  Mask:255.0.0.0
         inet6 addr: ::1/128 Scope:Host
         UP LOOPBACK RUNNING  MTU:65536  Metric:1
         RX packets:61438 errors:0 dropped:0 overruns:0 frame:0
         TX packets:61438 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1
         RX bytes:5382563 (5.3 MB)  TX bytes:5382563 (5.3 MB)

我手動添加了一個包含hosts.allow以下C:\Windows\System32\drivers\etc內容的文件:

sshd: 150.203.213.248

它沒有任何區別。

這是一個已知問題,在此處進行了描述:

https://github.com/PowerShell/Win32-OpenSSH/issues/1027

執行 sshd 並收集日誌時,請確保您是 SYSTEM。

將最新版本的內容提取到 C:\Program Files\OpenSSH (確保二進制位置僅對 SYSTEM、管理員組具有寫入權限。經過身份驗證的使用者應該並且只有讀取和執行權限。)

就我而言,在為“經過身份驗證的使用者”分配“讀取和執行”權限後,它就可以工作了。

請參考安裝文件https://github.com/PowerShell/Win32-OpenSSH/wiki/Install-Win32-OpenSSH#install-win32-openssh-test-release

引用自:https://serverfault.com/questions/881909