sshd service fails to start

Try the sshd test mode. It may point you to a reason for failure:

$ sshd -t

Refer to the test mode documentation here.


The problem, in our case was that we use a non-standard port for SSH. SELinux can restrict which ports are able to be used by a service. Apparently it gets confused sometimes and forgets that we had allowed that port?

We had to issue the following command to add our port (22222) to the list of available ports

semanage port -a -t ssh_port_t -p tcp 22222

Reference: http://sharadchhetri.com/2014/10/15/centos-7-rhel-7-change-openssh-port-number-selinux-enabled/


Well if you change the SSH port number you have to do some more things in CentOS 7.

Change SSH port editing ssdh_config file

vi /etc/ssh/sshd_config

For example change to: Port 2323

SELINUX only allow port 22 for ssh. Add new port context 2323. If you have't installed do the following

yum -y install policycoreutils-python
semanage port -a -t ssh_port_t -p tcp 2323

Check the port context for ssh

semanage port -l | grep ssh

Restart SSHD service

systemctl restart sshd.service

Add the port to firewall

firewall-cmd --permanent --zone=public --add-port=2323/tcp

Reload firewall

firewall-cmd --reload

Check listening

ss -tnlp|grep ssh

Try connecting again trough ssh

ssh root@<ipaddr> -p 2323

I also had this problem but solved it. My configuration is below.

PermitRootLogin no
port 22
MaxAuthTries 3
MaxSessions 2
AllowUsers ravikanth
AddressFamily any
ListenAddress 192.168.1.23

The service failed to start so I have just commented out the last line (#ListenAddress 192.168.1.23) then my server started successfully.

Note: I have turned off firewall (iptables) and SELinux.


You may want to try using the following setting:

RestartSec=5s

That would force your application to sleep for 5 seconds prior to a restart attempt. You can obviously vary the number of settings.

See here for details: