无法在端口 22 以外的其他端口登录远程 VPS

问题描述 投票:0回答:0

出于安全原因,我将 ssh 登录的端口更改为不同的号码。但是,一旦我这样做并尝试重新连接,我就会收到“连接超时错误”。 一旦我切换回端口 22,一切正常。

  1. 使用
    ssh [email protected]
    登录到我的VPS。
  2. 在 /etc/ssh/ 中,我更改了 sshd_config 文件以将端口设置为 717。
  3. 使用以下命令重新启动 ssh 守护程序:
    sudo systemctl restart sshd
  4. 使用
    systemctl status sshd
  5. 验证 ssh 守护进程已启动并正在运行
  6. 通过尝试在 1 中的第二个终端上登录,验证端口 22 不再工作。
  7. 这导致了预期的
    ssh: connect to host vps.ip.address port 22: Connection refused
  8. 尝试使用端口 717 通过 ssh 登录:
    ssh [email protected] -p 717
  9. 一段时间后我得到回应:
    ssh: connect to vps.ip.address port 717: Connection timed out
  10. 仍在我的 VPS 上的活动终端会话中验证服务器是否正确侦听端口 717:
    sudo grep Port /etc/ssh/sshd_config
    。输出是:
Port 717
#GatewayPorts no

  1. 检查防火墙设置以确保没有阻塞端口 717:
    sudo iptables -L
  2. 返回:
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  

  1. 检查 /var/log/auth.log 输出以验证仍在侦听端口 717:
Mar 13 08:18:20 localhost sshd[4883]: Server listening on 0.0.0.0 port 717.`
`Mar 13 08:18:20 localhost polkitd(authority=local): Unregistered Authentication Agent for unix-process:4863:4345392 (system bus name :1.35, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
  1. 在 /etc/ssh/sshd_config 中将端口改回端口 22 并重新启动 teh ssh 守护进程
  2. 就像在 1 下一样,通过 ssh 从第二个终端登录。
  3. 再次登录成功
port vps sshd
© www.soinside.com 2019 - 2024. All rights reserved.