Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
1、问题描述
在CentOS7.6上更改端口号时报错: Job for sshd.service failed because the control process exited with error code.See “systemctl status sshd.service” and “journalctl -xe” for details.
2、修改ssh端口号的方法
修改:vim /etc/ssh/sshd_config
将 “#Port 22” 改为 “Port 67122”
将 “#PermitRootLogin yes” 改为 “PermitRootLogin no”
重启:service sshd restart
重启后报错
3、原因分析
查看SElinux允许的ssh的端口号
semanage port -l | grep ssh
ssh_port_t tcp 22
没问题.(很多网上说这里有问题,使用semanage工具添加ssh端口号,semanage port -a -t ssh_port_t -p tcp 67122)
4、我的解决方法
后来我进到云服务器,看到
才醒悟过来,原来是我定义的端口值太大了..
注意看它给你的提示:See "systemctl status sshd.service" and "journalctl -xe" for details.
[root@VM-4-4-centos ssh]# journalctl -xe
Aug 04 14:50:31 VM-4-4-centos systemd[1]: Unit sshd.service entered failed state.
Aug 04 14:50:31 VM-4-4-centos systemd[1]: sshd.service failed.
Aug 04 14:51:01 VM-4-4-centos systemd[1]: Started Session 26 of user root.
-- Subject: Unit session-26.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-26.scope has finished starting up.
--
-- The start-up result is done.
Aug 04 14:51:01 VM-4-4-centos CROND[4370]: (root) CMD (flock -xn /tmp/stargate.lock -c '/usr/local/qcloud/stargate/admin/start.sh > /dev/null 2>&1 &
Aug 04 14:51:13 VM-4-4-centos systemd[1]: sshd.service holdoff time over, scheduling restart.
Aug 04 14:51:13 VM-4-4-centos systemd[1]: Stopped OpenSSH server daemon.
-- Subject: Unit sshd.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sshd.service has finished shutting down.
Aug 04 14:51:13 VM-4-4-centos systemd[1]: Starting OpenSSH server daemon...
-- Subject: Unit sshd.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sshd.service has begun starting up.
Aug 04 14:51:13 VM-4-4-centos sshd[4416]: /etc/ssh/sshd_config line 17: Badly formatted port number.
Aug 04 14:51:13 VM-4-4-centos systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
Aug 04 14:51:13 VM-4-4-centos systemd[1]: Failed to start OpenSSH server daemon.
-- Subject: Unit sshd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sshd.service has failed.
--
-- The result is failed.
Aug 04 14:51:13 VM-4-4-centos systemd[1]: Unit sshd.service entered failed state.
Aug 04 14:51:13 VM-4-4-centos systemd[1]: sshd.service failed.
Aug 04 14:51:13 VM-4-4-centos sshd[4416]: /etc/ssh/sshd_config line 17: Badly formatted port number.
修改成规范的端口值后,重启
systemctl restart sshd.service
或service sshd restart
注意:本文归作者所有,未经作者允许,不得转载