Fab*_*ira 9 ssh powershell openssh windows-10 windows-subsystem-for-linux
我的主机是Windows 10(版本 20H2,内部版本 19042.746),安装了 WSL2(如下所示:https: //learn.microsoft.com/en-us/windows/wsl/install-win10)。
\n安装OpenSSH后(如下所示:https: //learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse和https://www.hanselman.com/blog/the-easy-way -how-to-ssh-into-bash-and-wsl2-on-windows-10-from-an-external-machine ),在PowerShell 中以 admin身份使用以下命令:
\n> Get-WindowsCapability -Online | ? Name -like \'OpenSSH*\'\n\nName : OpenSSH.Client~~~~0.0.1.0\nState : Installed\n\nName : OpenSSH.Server~~~~0.0.1.0\nState : NotPresent\n\n> Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0\n> Start-Service sshd\n> Get-Service sshd\n> Set-Service -Name sshd -StartupType \'Automatic\'\n> New-ItemProperty -Path "HKLM:\\SOFTWARE\\OpenSSH" -Name DefaultShell -Value "C:\\Windows\\System32\\bash.exe"\n> Get-WindowsCapability -Online | ? Name -like \'OpenSSH*\'\n\nName : OpenSSH.Client~~~~0.0.1.0\nState : Installed\n\nName : OpenSSH.Server~~~~0.0.1.0\nState : Installed\nRun Code Online (Sandbox Code Playgroud)\n我检查了 Windows 防火墙是否包含 OpenSSH 服务作为活动且开放的入站规则。
\n我也用telnet检查过:
\n> telnet localhost 22\nSSH-2.0-OpenSSH_for_Windows_7.7\nRun Code Online (Sandbox Code Playgroud)\n直到这里似乎一切都好!
\n现在问题发生了,也在PowerShell(或cmd )中运行命令:
\n> ssh localhost\nConnection reset by ::1 port 22\nRun Code Online (Sandbox Code Playgroud)\n有人遇到同样的问题吗(运行在:Windows 10 + PowerShell/cmd + OpenSSH)?
\n有谁知道为什么会出现这个问题?
\n有谁知道如何解决这个问题?
\n谢谢!
\n\n\n=============更多信息=============
\n
按照另一个命令进行调试:
\n> sshd -d\ndebug1: sshd version OpenSSH_for_Windows_7.7, LibreSSL 2.6.5\ndebug1: key_load_private: Permission denied\ndebug1: key_load_public: Permission denied\nCould not load host key: __PROGRAMDATA__\\\\ssh/ssh_host_rsa_key\ndebug1: key_load_private: Permission denied\ndebug1: key_load_public: Permission denied\nCould not load host key: __PROGRAMDATA__\\\\ssh/ssh_host_ecdsa_key\ndebug1: key_load_private: Permission denied\ndebug1: key_load_public: Permission denied\nCould not load host key: __PROGRAMDATA__\\\\ssh/ssh_host_ed25519_key\nsshd: no hostkeys available -- exiting.\nRun Code Online (Sandbox Code Playgroud)\n似乎__PROGRAMDATA__指的是 Windows 环境变量%PROGRAMDATA%,即指向C:\\ProgramData.
> ls C:\\ProgramData\\ssh\n\n Diret\xc3\xb3rio: C:\\ProgramData\\ssh\n\n\nMode LastWriteTime Length Name\n---- ------------- ------ ----\nd----- 25/01/2021 19:59 logs\n-a---- 27/01/2021 02:03 2252 sshd_config\n-a---- 25/01/2021 19:59 668 ssh_host_dsa_key\n-a---- 25/01/2021 19:59 628 ssh_host_dsa_key.pub\n-a---- 25/01/2021 19:59 227 ssh_host_ecdsa_key\n-a---- 25/01/2021 19:59 200 ssh_host_ecdsa_key.pub\n-a---- 25/01/2021 19:59 432 ssh_host_ed25519_key\n-a---- 25/01/2021 19:59 120 ssh_host_ed25519_key.pub\n-a---- 25/01/2021 19:59 420 ssh_host_rsa_key.pub\nRun Code Online (Sandbox Code Playgroud)\n按照 sshd 配置中的内容进行操作:
\n> cat C:\\WINDOWS\\System32\\OpenSSH\\sshd_config_default\n# This is the sshd server system-wide configuration file. See\n# sshd_config(5) for more information.\n\n# The strategy used for options in the default sshd_config shipped with\n# OpenSSH is to specify options with their default value where\n# possible, but leave them commented. Uncommented options override the\n# default value.\n\n#Port 22\n#AddressFamily any\n#ListenAddress 0.0.0.0\n#ListenAddress ::\n\n#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key\n#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key\n#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key\n#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key\n\n# Ciphers and keying\n#RekeyLimit default none\n\n# Logging\n#SyslogFacility AUTH\n#LogLevel INFO\n\n# Authentication:\n\n#LoginGraceTime 2m\n#PermitRootLogin prohibit-password\n#StrictModes yes\n#MaxAuthTries 6\n#MaxSessions 10\n\n#PubkeyAuthentication yes\n\n# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2\n# but this is overridden so installations will only check .ssh/authorized_keys\nAuthorizedKeysFile .ssh/authorized_keys\n\n#AuthorizedPrincipalsFile none\n\n# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts\n#HostbasedAuthentication no\n# Change to yes if you don\'t trust ~/.ssh/known_hosts for\n# HostbasedAuthentication\n#IgnoreUserKnownHosts no\n# Don\'t read the user\'s ~/.rhosts and ~/.shosts files\n#IgnoreRhosts yes\n\n# To disable tunneled clear text passwords, change to no here!\nPasswordAuthentication yes\n#PermitEmptyPasswords no\n\n#AllowAgentForwarding yes\n#AllowTcpForwarding yes\n#GatewayPorts no\n#PermitTTY yes\n#PrintMotd yes\n#PrintLastLog yes\n#TCPKeepAlive yes\n#UseLogin no\n#PermitUserEnvironment no\n#ClientAliveInterval 0\n#ClientAliveCountMax 3\n#UseDNS no\n#PidFile /var/run/sshd.pid\n#MaxStartups 10:30:100\n#PermitTunnel no\n#ChrootDirectory none\n#VersionAddendum none\n\n# no default banner path\n#Banner none\n\n# override default of no subsystems\nSubsystem sftp sftp-server.exe\n\n# Example of overriding settings on a per-user basis\n#Match User anoncvs\n# AllowTcpForwarding no\n# PermitTTY no\n# ForceCommand cvs server\n\nMatch Group administrators\n AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
20931 次 |
| 最近记录: |