PowerShell SSH 仅适用于 LAN,但不适用于 Internet

问题描述

我设置了防火墙例外,一切正常

通过家庭互联网 DHCP 工作

甚至尝试关闭域和家庭的防火墙都无济于事。

这是我的代码(只是指南):

# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

# Start the sshd service
Start-Service sshd

# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

# Confirm the firewall rule is configured. It should be created automatically by setup.
Get-NetFirewallRule -Name *ssh*

# There should be a firewall rule named "OpenSSH-Server-In-TCP",which should be enabled
# If the firewall does not exist,create one
New-NetFirewallRule -Name sshd -displayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

这里是我用代码做的事情的概要。 SSH client to client hosting in PowerShell

解决方法

您需要打开端口 22/TCP 才能在 LAN 外使用 SSH。

这通常可以在您的路由器配置中实现,也可以通过联系您的提供商来实现。成功执行此操作后,您可以使用 WAN IP 访问网络外的 SSH。