You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows系统OpenSSH本地连接被重置问题求助

Windows系统OpenSSH本地连接被重置问题求助

我现在在Windows系统上配置OpenSSH遇到了麻烦,尝试过系统自带的安装方式,也手动从二进制文件安装过——把OpenSSH文件放到了C:\Program Files路径下完成安装。

OpenSSH服务器和代理看起来配置都没问题,但我尝试ssh连接localhost的时候,一直报错:

Connection reset by ::1 port 22

以下是我运行的一些调试命令及结果:

Get-Service ssh-agent

Status   Name               DisplayName
------   ----               -----------
Running  ssh-agent          OpenSSH Authentication Agent
Get-Service sshd

Status   Name               DisplayName
------   ----               -----------
Running  sshd               OpenSSH SSH Server
netstat -nao | find /i '":22"'

TCP    0.0.0.0:22             0.0.0.0:0              LISTENING       5680
TCP    [::]:22                [::]:0                 LISTENING       5680
Get-NetFirewallRule -Name *OpenSSH-Server* |select Name, DisplayName, Description, Enabled

Name                  DisplayName           Description Enabled
----                  -----------           ----------- -------
OpenSSH-Server-In-TCP OpenSSH Server (sshd)             True
whoami

pcname\m.ceradini
ssh pcname\m.ceradini@localhost

Connection reset by ::1 port 22

我用的是默认的sshd_config,按照其他教程的建议,我尝试注释掉了配置里的Match Group Administrators,但问题还是没解决。有没有人知道这是怎么回事?该怎么修复这个连接重置的问题?


更新内容

下面是针对一些疑问的回复,目前ssh连接本地用户还是不行。我总结一下自己后续做的操作:

  • 卸载了OpenSSH
  • 删除了所有.ssh和OpenSSH相关的文件夹
  • 通过Windows设置GUI重新安装了OpenSSH客户端和服务器,然后重启了电脑
  • 检查了所有SSH相关命令和服务都能正常运行(Get-Command ssh、Get-Command sshd、Get-Command ssh-agent、Get-Service sshd、Get-Service ssh-agent)
  • 为当前用户创建了新的密钥
  • 将公钥添加到了.ssh文件夹下的authorized_keys中
  • 注释了sshd_config里的Match Group administrators
  • 在sshd_config中启用了PubkeyAuthentication
  • 确认sshd服务处于运行状态

再次调试的结果:

Get-Service sshd

Status   Name               DisplayName
------   ----               -----------
Running  sshd               OpenSSH SSH Server

有朋友提醒说,默认配置的sshd不会处理回环设备的连接,localhost通常连不上,除非之前在对应端口开了隧道,建议我试试下面的命令:

ssh pcname

结果正常返回当前用户:

whoami

pcname\m.ceradini

然后我试了带用户名的命令,结果解析不了主机:

ssh -v pcname\m.ceradini

OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
ssh: Could not resolve hostname pcname\\m.ceradini: No such host is known.

朋友又建议如果主机找不到的话,用本地IP而不是127.0.0.1或::1,我试了:

ssh -v 192.168.83.185

调试输出如下:

debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
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
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:v7C8pJ1ci+e/ZJKhgyIvZfENRyQHd0sUJSXv8PXIEDM
debug1: load_hostkeys: fopen C:\\Users\\m.ceradini/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
debug1: Host '192.168.83.185' is known and matches the ED25519 host key.
debug1: Found key in C:\\Users\\m.ceradini/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: sssapisa\\m.ceradini@TNE-Matteo ED25519 SHA256:ugTj7Iu5c0ZbiXgF6yMPO8Hru3rLp5ynP+Aku15WKX0 agent
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_rsa RSA SHA256:WgcHzwF1tPBwnvdmy9KriQjn+qLuDbOhR80Bmpw10O0
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_ecdsa_sk
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_ed25519
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_ed25519_sk
debug1: Will attempt key: C:\\Users\\m.ceradini/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com,webauthn-sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: sssapisa\\m.ceradini@TNE-Matteo ED25519 SHA256:ugTj7Iu5c0ZbiXgF6yMPO8Hru3rLp5ynP+Aku15WKX0 agent
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Offering public key: C:\\Users\\m.ceradini/.ssh/id_rsa RSA SHA256:WgcHzwF1tPBwnvdmy9KriQjn+qLuDbOhR80Bmpw10O0
debug1: Server accepts key: C:\\Users\\m.ceradini/.ssh/id_rsa RSA SHA256:WgcHzwF1tPBwnvdmy9KriQjn+qLuDbOhR80Bmpw10O0
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.83.185 ([192.168.83.185]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: filesystem full
debug1: ENABLE_VIRTUAL_TERMINAL_INPUT is supported. Reading the VTSequence from console
debug1: ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported. Console supports the ansi parsing
client_loop: send disconnect: Connection reset

朋友还说ssh默认会用当前用户,不用特意指定用户名,这样能排除错误来源,猜测我不该用pcname\m.ceradini,只用m.ceradini就行,但我不是Windows资深用户,没法验证这点。不过我已经试过所有可能的用户名组合了,结果还是一样的连接重置。

备注:内容来源于stack exchange,提问作者ceradini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 15:20:34