如何通过互联网通过 SSH 进入 Linux 服务器

如何通过互联网通过 SSH 进入 Linux 服务器

我到处都找过了,但仍然没有得到我想要的结果。

当在同一个本地网络上时,我可以使用 ssh 进入我的 linux ubuntu 服务器[电子邮件保护] 我也可以使用我的公共 IP 通过 ssh 进入它。我使用 TCP 转发端口 22,并将 IP 设置为服务器的私有 IP。当我尝试通过互联网(不在同一个本地网络上)通过 ssh 进入它时,连接总是超时。在 canyouseemee.org 上,端口似乎没有打开。我不知道自己在做什么,我已经看过 stack exchange 和其他地方的许多教程,但仍然没有进展。我一定是在服务器上做错了什么,因为我已经在转发端口 22。如果需要任何其他信息,请告诉我。

顺便说一句,了解我在其上运行的 minecraft 服务器并且可以成功转发端口 25565 可能会有所帮助。

此外,我有一个在线 Web 应用程序,它打开了服务器的仪表板,并且也有一个端口。我还可以转发该端口,并且它成功运行。老实说,我不知道发生了什么……除了 22 之外的其他端口都在运行。

这是 sshd 配置:

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem sftp  /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
PasswordAuthentication yes
GatewayPorts yes
AllowTcpForwarding yes

编辑:感谢评论中的某人,他们让我知道我的 ISP 可能阻止了对端口 22 的访问。我更改了 ssh 配置文件中的端口,它就起作用了。

答案1

我想您可能需要要求您的 ISP 允许该端口(或所有端口,或任何其他端口)上的传入流量。出于安全原因,某些 ISP 会阻止端口 22 上的传入流量。

在向 ISP 询问任何事情之前,您可以尝试使用其他端口。我建议您先尝试使用 80 或 443,因为它们通常是为 HTTP 流量保留的,而且 ISP 在大多数情况下允许传入流量。

请注意,如果是这种情况,则无需在 SSH 服务器上更改任何内容,而是可以执行如下端口转发:

{public-ip}:80 > {lan-ip}:22

相关内容