CentOS 6: Setup SSH to run on startup

CentOS Bash
CentOS Bash

By default with CentOS 6 SSH is not configured to run on startup.

Meaning you will have to activate the service every time before being able to use SSH on the CentOS server.

To enable SSH to run on boot run the following command.

chkconfig sshd on

This can be applied to any service you want to run on boot. Once this is done restart the server and SSH will be started.

  • matt

    Fantastic, just what i needed

  • daniel, this is the second time you are making my life easier.
    Keep up the good work !

  • Craig

    No need to restart the server. Just do:

    service sshd start

    • Restarting the server will allow you to test to make sure SSH is working on boot.

  • Pingback: Adding secure connectivity for remote administration of CentOS with NX Server |()

  • J. Canuck

    Nice suggestion, but still doesn’t seem to work on my CentOS 6.4 box. Whenever I restart the system, the sshd service shows up as ‘dead’. If I do a manual start, all is well, but I can’t for the life of me get it to start automatically on reboot.

  • Try

    systemctl enable sshd

    that works as well i believe

    • J. Canuck

      Well, as it turns out, there were a couple of issues interaction with each other — here is a summary of the resolution (huge thanks to ‘Wolfy’ on the #centos irc channel).

      1\ in my sshd_config, I had sshd bind to my fixed ip:

      port 22
      ListenAddress my.fixed.ip.here:22

      2\ if I commented out the ListenAddress line, then sshd came up on reboot, as expected. But, if I uncommented ListenAddress, then sshd would not come up on boot. Although I could start if from console.

      3\ this was the big clue — it suggested (subsequently confirmed) that sshd was trying to come up before the NIC was ready (i.e., before eth0 was up). I confirmed this by adding ‘sleep 5s’ to the top of /etc/init.d/sshd.

      So, root of the problem identified. For some reason, eth0 was taking ‘too long’ to come up.

      4\ tried newest NIC drivers from ElRepo — didn’t help. While the sleep 5s trick worked, I was now puzzled over why eth0 was taking so long to come up.

      5\ a random web search gave me a clue. There was a problem in the way I’d set hostname in /etc/hosts and /etc/sysconfig/network (the search lead to a post where someone had pointed out that sometime eth0 is slow coming up because of how hostnames are set).

      And, lo and behold, once I’d tweaked hosts and network, eth0 came up much faster (fast enough that I don’t seem to need the sleep 5s trick anymore — although its a good trick to know).

      Hopefully, this might help out someone else who has this problem (and there seems to be no shortage of folks who have had issues getting sshd to start on boot).

  • Craig Twofoot

    Thanks! Worked great.