我已经成功设置了通过 Windows 10 可选功能部分运行的 OpenSSH 服务器和客户端。
每当我尝试登录服务器时,系统都会要求我输入密码。我只为我的 Windows 10 PC 配置了一个密码,那就是我的 Microsoft 帐户的密码。但是,服务器拒绝使用该密码进行访问。我还没有为 SSH 服务器设置任何密码。
服务器的默认密码是什么?
sshd_config
以下是文件夹中文件的内容%PROGRAMDATA%\ssh\
:
# 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 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
这是输出Get-NetFirewallRule -Name *ssh*
:
Name : OpenSSH-Server-In-TCP
DisplayName : OpenSSH SSH Server (sshd)
Description : Inbound rule for OpenSSH SSH Server (sshd)
DisplayGroup : OpenSSH Server
Group : OpenSSH Server
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
Name : SshProxy-Service
DisplayName : SshProxy-Service-Private
Description : SSH Server Proxy Service
DisplayGroup : Ssh Server
Group : Ssh Server
Enabled : True
Profile : Private
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
Name : SshProxy-Service-Domain
DisplayName : SshProxy-Service-Domain
Description : SSH Server Proxy Service
DisplayGroup : Ssh Server
Group : Ssh Server
Enabled : True
Profile : Domain
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
输出[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
:
<my_name>\USER
答案1
我还没有为 SSH 服务器设置任何密码。服务器的默认密码是什么?
没有。
每当我尝试登录服务器时,系统都会要求我输入密码。我只为我的 Windows 10 PC 配置了一个密码,那就是我的 Microsoft 帐户的密码。但是,服务器拒绝使用该密码进行访问。
您尝试使用错误的用户名进行连接。您应该使用ssh Machine_Name\Username@localhost
来连接服务器。
为什么我需要提供 \USER 部分?
您必须明确指出要使用哪个用户名才能连接到 OpenSSH 服务器。您还指出您使用了语法,ssh <my_name>@localhost
这表明用户名是您的机器名称,而不是您的实际用户名。
自从<my_name>
不是机器上的实际用户名,密码验证失败,你实际上必须使用Username
并明确指出它在机器上Machine_Name\Username
。
的输出[System.Security.Principal.WindowsIdentity]::GetCurrent().Name
将指示应该使用什么。
答案2
它可能不接受有效的用户名和密码的另一个原因是配置的 shell 错误。
你可以检查一下
reg query HKLM\SOFTWARE\OpenSSH /v DefaultShell
要将其设置为 Powershell,如果您在默认目录中有它:
reg add HKLM\SOFTWARE\OpenSSH /v DefaultShell /d C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
答案3
在 cmd 中写入
whoami
,它会给你一个文本,复制整个文本,我说的整个意思是整个。在这个例子中,假设我得到了nick\hp
我的输出。现在在 cmd 中,输入
ssh nick\hp@localhost
,然后按 Enter。它会要求输入密码,在这里输入你的 Microsoft 帐户的密码。然后你就可以成功 ssh 登录了。
答案4
我遇到过类似的问题。 ssh 登录一直正常工作,直到有一天。 不确定到底发生了什么。 我可能尝试通过 samba 共享 Windows 文件夹,从而搞砸了一些 openssh 设置。 无论如何,这里是解决方案:
创建新的 Windows 用户
就是这样。我可以用新帐户正常登录。似乎旧帐户的 ssh 密码在我未执行任何操作的情况下就更改了。