如何解决sshd 导致 Windows 10 OpenSSH 授权密钥错误
在阅读了这里的精彩帖子后得到了很多支持,我的第一个问题是:
我尝试在 Mac 和 Windows 10 (20H2) 之间使用密钥设置 ssh。 到现在为止我做了什么:
- 在 Mac 上生成密钥,通过自动登录到 raspberry 测试了 pub 密钥,一切正常。
- 将pubkey复制到win10,根据设置访问权限 https://askme4tech.com/how-install-and-configure-open-ssh-server-windows-10
- 将 sshd_config 更改为此
- 如果我尝试 ssh win10,我得到(使用 ssh -v)(只有最后几行):
...
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.2.157 ([192.168.2.157]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
client_loop: send disconnect: Broken pipe
-
万一我在 Win10 上停止 sshd 并启动它,而不是将其作为服务启动,只需使用
c:\>sshd.exe
一切正常。我在手动启动调试模式 sshd -d 时发现了这一点。 -
由于我对 Win10 的了解有限,我不知道在哪里查看或修复此问题,所以感谢您的提示!
马努
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible,but leave them commented. Uncommented options override the
# default value.
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords,change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
ClientAliveInterval 60
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp sftp-server.exe
# Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
#Match Group administrators
# AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys
解决方法
如果我在 Win10 上停止 sshd 并且不将其作为服务启动,只需使用 c:>sshd.exe
- 在一种情况下,sshd 作为服务运行,可能带有 LocalSystem account
- 另一方面,从命令行,您正在以您的身份(您的 Windows 帐户)运行 sshd。
环境会不一样,特别是对于“authorized_keys
”文件。
如the documentation中所述:
在 Windows 中,sshd
默认从 %programdata%\ssh\sshd_config
读取配置数据,或者可以通过使用 sshd.exe
参数启动 -f
来指定不同的配置文件。
如果文件不存在,sshd
会在服务启动时使用默认配置生成一个。
在将 ssh 守护程序作为 Windows 服务运行时激活日志,如 seen here:
打开管理员 powershell 提示符并运行:
notepad C:\ProgramData\ssh\sshd_config
找到“# Logging
”部分并添加这两行。
SyslogFacility LOCAL0
LogLevel DEBUG3
运行 services.msc
并在服务运行时重新启动它,如果它停止则启动它。
确保将其设置为以系统帐户运行。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。