密码身份验证在 Windows 上的 ssh 中不起作用

Posted

技术标签:

【中文标题】密码身份验证在 Windows 上的 ssh 中不起作用【英文标题】:Password authentication is not working in ssh on windows 【发布时间】:2020-11-06 08:16:40 【问题描述】:

我尝试安装 Windows OpenSSH 服务器功能,还尝试在 C:/Program Files/OpenSSH 中手动安装 OpenSSH,但是当我尝试连接时要求输入正确的密码,但始终显示权限被拒绝。它工作正常,但一段时间后开始面临这个问题。我尝试使用 -d 选项手动运行 sshd 服务器,它提供了以下日志

debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9p1 Debian-10+deb10u2
debug1: match: OpenSSH_7.9p1 Debian-10+deb10u2 pat OpenSSH* compat 0x04000000
debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: SSH2_MSG_KEXINIT received [preauth]
debug1: kex: algorithm: curve25519-sha256 [preauth]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256 [preauth]
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none [preauth]
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none [preauth]
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth]
debug1: rekey out after 134217728 blocks [preauth]
debug1: SSH2_MSG_NEWKEYS sent [preauth]
debug1: Sending SSH2_MSG_EXT_INFO [preauth]
debug1: expecting SSH2_MSG_NEWKEYS [preauth]
debug1: SSH2_MSG_NEWKEYS received [preauth]
debug1: rekey in after 134217728 blocks [preauth]
debug1: KEX done [preauth]
debug1: userauth-request for user aawais@domain service ssh-connection method none [preauth]
debug1: attempt 0 failures 0 [preauth]
debug1: user domain\\aawais matched group list administrators at line 84
User domain\\aawais not allowed because shell c:\\program files\\powershell\\7\\pwsh.exe does not exist
debug1: userauth-request for user aawais@domain service ssh-connection method keyboard-interactive [preauth]
debug1: attempt 1 failures 0 [preauth]
debug1: keyboard-interactive devs  [preauth]
debug1: auth2_challenge: user=aawais@domain devs= [preauth]
debug1: kbdint_alloc: devices '' [preauth]
debug1: userauth-request for user aawais@domain service ssh-connection method password [preauth]
debug1: attempt 2 failures 1 [preauth]
debug1: Windows authentication failed for user: NOUSER domain: . error: 1326 

以下是我的 sshd_config 文件

# 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 yes
#StrictModes yes
MaxAuthTries 600
#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 0
#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


这个问题的原因可能是什么?

【问题讨论】:

我认为你应该带着这个去superuser,因为这不是一个与编程相关的问题。 【参考方案1】:

默认 shell 位置不正确,我在问题 i-e 中提到的服务器调试日志中发现了这一点

User domain\\aawais not allowed because shell c:\\program files\\powershell\\7\\pwsh.exe does not exist

执行以下命令设置默认shell

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force

【讨论】:

以上是关于密码身份验证在 Windows 上的 ssh 中不起作用的主要内容,如果未能解决你的问题,请参考以下文章

如何使用没有密码的 SSH 身份验证连接到 Windows SFTP 服务器? [复制]

GitLab SSH要求输入密码(未知密码)身份验证失败

通过 windows 命令提示符使用密码验证执行 ssh

禁用 SSH 的密码身份验证无法按预期工作 Ubuntu 14.04 LTS

我在服务器上的iis上的身份验证选项中去掉了匿名访问,启用了集成windows身份验证

仅针对特定用户的 SSH 身份验证绕过密码身份验证