将 sshd_config 更改为端口 2222 后无法重新启动 SSH 守护程序

Ful*_*ack 6 linux ssh openssh ubuntu

我一直在环顾四周,但找不到解决我遇到的问题的方法。我正在运行Ubuntu 16.04 LTS,我按照 Ubuntu页面上的说明2222通过更新sshd_config文件来更改 SSH 端口。

# What ports, IPs and protocols we listen for
Port 2222
Run Code Online (Sandbox Code Playgroud)

sudo systemctl restart sshd.service但是,当我执行命令时,我只收到以下错误:

Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.
Run Code Online (Sandbox Code Playgroud)

然后我执行命令systemctl status ssh.service并得到

? ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2016-09-07 23:24:04 EDT; 1min 28s ago
  Process: 16813 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
 Main PID: 16813 (code=exited, status=255)

Sep 07 23:24:04 sys-0 systemd[1]: Starting OpenBSD Secure Shell server...
Sep 07 23:24:04 sys-0 systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
Sep 07 23:24:04 sys-0 systemd[1]: Failed to start OpenBSD Secure Shell server.
Sep 07 23:24:04 sys-0 systemd[1]: ssh.service: Unit entered failed state.
Sep 07 23:24:04 sys-0 systemd[1]: ssh.service: Failed with result 'exit-code'.
Run Code Online (Sandbox Code Playgroud)

错误是什么意思,我该如何解决?

Pab*_*o A 12

正如@techraf 所说,很可能您在/etc/ssh/sshd_config. 尝试sshd 测试模式

$ sudo sshd -t
/etc/ssh/sshd_config: line 1: Bad configuration option: sds
Run Code Online (Sandbox Code Playgroud)

手册页

  • -t 测试模式。只检查配置文件的有效性和密钥的完整性。这对于可靠地更新 sshd 很有用,因为配置选项可能会改变。
  • -T 扩展测试模式。检查配置文件的有效性,将有效配置输出到stdout然后退出。或者,可以通过使用一个或多个-C选项指定连接参数来应用匹配规则。


Mat*_*ark 3

您正在使用的系统上运行吗SELinux?这可能是拒绝端口绑定;尝试添加新规则。

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