Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not sure why it isn't starting or why its preventing me from connecting, i get this error:

sshd.service - OpenSSH Daemon
    Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: failed (Result: start-limit) since Wed 2013-09-11 08:45:13 BST; 1min 21s ago
  Process: 701 ExecStart=/usr/bin/sshd -D (code=exited, status=1/FAILURE)

Sep 11 08:45:13 alarmpi systemd[1]: sshd.service: main process exited, code=exited, status=1/FAILURE
Sep 11 08:45:13 alarmpi systemd[1]: Unit sshd.service entered failed state.
Sep 11 08:45:13 alarmpi systemd[1]: sshd.service holdoff time over, scheduling restart.
Sep 11 08:45:13 alarmpi systemd[1]: Stopping OpenSSH Daemon...
Sep 11 08:45:13 alarmpi systemd[1]: Starting OpenSSH Daemon...
Sep 11 08:45:13 alarmpi systemd[1]: sshd.service start request repeated too quickly,    refusing to start.
Sep 11 08:45:13 alarmpi systemd[1]: Failed to start OpenSSH Daemon.
Sep 11 08:45:13 alarmpi systemd[1]: Unit sshd.service entered failed state.

On the advice of #amrith I ran sshd -t which indicated that the key had not been generate . I generated this using ssh-keygen -A on the advice given in this forum then running systemctl status showed that I am still not running the Daemon. I've attached the error below, sadly I don't know ho Re-running sshd -t gives no messages now.

sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: inactive (dead)

Sep 11 12:04:42 alarmpi systemd[1]: Started OpenSSH Daemon.
Sep 11 12:04:42 alarmpi sshd[289]: fatal: Cannot bind any address.
Sep 11 12:04:42 alarmpi systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
Sep 11 12:04:42 alarmpi systemd[1]: Unit sshd.service entered failed state.
Sep 11 12:04:42 alarmpi systemd[1]: sshd.service holdoff time over, scheduling restart.
Sep 11 12:04:42 alarmpi systemd[1]: Stopping OpenSSH Daemon...
Sep 11 12:04:42 alarmpi systemd[1]: Starting OpenSSH Daemon...
Sep 11 12:04:42 alarmpi systemd[1]: sshd.service start request repeated too quickly, refusing to start.
Sep 11 12:04:42 alarmpi systemd[1]: Failed to start OpenSSH Daemon.
Sep 11 12:04:42 alarmpi systemd[1]: Unit sshd.service entered failed state.
share|improve this question

Try sshd -t (the sshd test mode). It may point you to a reason for failure.

Refer to the test mode documentation here.

share|improve this answer
    
I didn't know about sshd -t it resolved some stuff. I saw that there were no keys, so I've generated those but no dice upon restart and reboot. – aCoolBean Sep 11 '13 at 11:16
    
This worked for me, I got "/etc/ssh/sshd_config line 97: Bad SSH2 mac spec . . ." – jeremiah Jan 8 '15 at 10:05

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/

share|improve this answer
1  
It should be semanage port -a -t ssh_port_t -p tcp 22222 – FrankerZ Dec 28 '15 at 12:58
    
I just edited in the comment by @FrankerZ as the answer is useless otherwise. – dauer Jan 1 at 18:23

Cannot bind any address

If it tries to bind to a port (eg. by default: 22) below 1024, it needs root privilege to do that. Did you run service sshd start or something like that as root? Try editing the sshd.conf configuration file, set the bind address to a port greater than 1024 (eg. 1122) and run it as a simple user!

share|improve this answer

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.

share|improve this answer

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:

share|improve this answer
    
I upvoted this answer, because it contains useful information about how to fix the issue when the problem is in systemd and not the actual service (sshd in the OP case). I've had services with restart=always fail and not be restarted, several times. This answer might actually solve that issue with systemd. (Eventhough it is not directly related to the OP question). – MattBianco Jul 24 '15 at 6:04

I had the same problem and the easiest solution I came through was to remove openssh and install it again.

 yum remove openssh

and then:

 yum install openssh openssh-server openssh-clients

then you can start sshd service:

 service sshd start
share|improve this answer

Well if you change the SSH port number you have to do some more thinks 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
share|improve this answer

protected by Community Jun 18 at 9:51

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.