Win10配置OpenSSH服务

发布时间 2023-04-07 18:24:28作者: rthete

1. 设置—>应用—>可选功能,安装OpenSSH服务

设置—>应用—>可选功能

2. 开启服务

以管理员身份运行Windows Powershell,开启ssh服务

PS C:\Windows\system32> net start sshd

Win+R,输入services.msc,打开Win10服务设置,启动类型改为自动

服务

启动类型

3. 更改服务端ssh端口

C:\Windows\System32\OpenSSH 中sshd_config_default修改内容并另存为sshd_config

更改ssh配置

# my config
Port 19964
PermitRootLogin yes
PasswordAuthentication yes

4. 修改防火墙权限

PS C:\Windows\system32> New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 19964

Name                          : sshd
DisplayName                   : OpenSSH Server (sshd)
Description                   :
DisplayGroup                  :
Group                         :
Enabled                       : True
Profile                       : Any
Platform                      : {}
Direction                     : Inbound
Action                        : Allow
EdgeTraversalPolicy           : Block
LooseSourceMapping            : False
LocalOnlyMapping              : False
Owner                         :
PrimaryStatus                 : OK
Status                        : 已从存储区成功分析规则。 (65536)
EnforcementStatus             : NotApplicable
PolicyStoreSource             : PersistentStore
PolicyStoreSourceType         : Local
RemoteDynamicKeywordAddresses :

5. 重启ssh服务

PS C:\Windows\system32> net stop sshd

OpenSSH SSH Server 服务已成功停止。

PS C:\Windows\system32> net start sshd
OpenSSH SSH Server 服务正在启动 .
OpenSSH SSH Server 服务已经启动成功。

6. 在客户端进行连接

问题:无法连接,使用-v进行debug

C:\Users\reika>ssh -p 19964 1@<ip_address> -v
OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to <ip_address> [<ip_address>] port 19964.
debug1: connect to address <ip_address> port 19964: Connection timed out
ssh: connect to host <ip_address> port 19964: Connection timed out

继续ping 远程主机,ping不通,最后发现是客户端网络问题,解决后正常连接。

输入exit退出连接。

7. ssh jump

C:\Users\reika>ssh -J <jump_username>@<jump_ip_address>:<jump_port> <username>@<ip_address>

ssh jump

参考资料

推荐阅读 | 在家如何搞学术:远程桌面、ssh、跳板机攻略(针对Win10)