在 CentOS 7 上更改端口后 SSH 失败

Nik*_*ikk 3 ssh centos centos7

更改端口后。

并重新启动 SSH 服务,它对我失败了。

我跑的时候得到以下信息systemctl status sshd.service

sshd.service: main process exited, code=exited, status=255/n/a
Unit sshd.service entered failed state.
sshd.service failed.
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何建议(newb here)?

Jak*_*uje 8

要允许sshd运行在默认 22 以外的端口上,您需要调整 SELinux 策略,否则将阻止其绑定端口。该过程在您要更改的行上方的几行中进行了说明sshd_config

# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
Run Code Online (Sandbox Code Playgroud)

因此,在您的情况下,只需从 root shell 运行(或使用sudo):

semanage port -a -t ssh_port_t -p tcp 977
Run Code Online (Sandbox Code Playgroud)

然后再次尝试重新启动该服务。如果它不能解决您的问题,请查看日志并更新问题。