我已經成功設定了透過 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
。
will的輸出[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 密碼已更改,而我沒有執行任何操作。