When I type in service sshd restart I get a sshd: unrecognized service error.

I do have, in /etc/ssh/ a file sshd_config that I use to set config. I can also putty into the Ubuntu box (it is remote).

When I type in /etc/init.d/sshd restart I get No such file or directory

Under /usr/sbin/ there is an sshd file, but it is binary.

Is something wrong with my sshd? What do I do to fix this? To be clear, I want to be able to type service sshd restart (like all the online tutourials say) to be able to, well, restart my sshd. So that my port changes take effect.

  • post the output of ls /etc/init.d | grep ssh – Avinash Raj May 5 '14 at 3:49

Ubuntu calls the service ssh, not sshd.

service ssh restart

The service is also controlled by upstart, and not sysvinit. So you'll find it at /etc/init/ssh.conf instead of /etc/init.d/ssh.

  • 6
    This answer no longer applies as of Ubuntu version 15. The System 5 rc script notion is now doubly out of date. For updated answers, see askubuntu.com/questions/653865 . – JdeBP Dec 30 '15 at 9:30
  • 3
    The first part of the answer still applies. Also note it should be sudo service ssh restart – Sridhar Sarnobat Jan 22 '17 at 20:25
  • 'sudo service ssh restart' works fine on ubuntu xenial. – Binita Bharati May 26 '18 at 6:39

Most importantly you should have permissions to do so. Most of the problem like cannot start process or cannot find some file are due to permissions. Use sudo before any command.

Now for ssh you can simply do

sudo stop ssh
sudo start ssh

This leverages upstart

  • 23
    this is really bad for remote servers, you can log yourself out with that first command and it's not automatically restarted. – therealmarv Aug 23 '16 at 21:03
  • 1
    @therealmarv reminds me of my first ip-tables remote configuration. "iptables -A INPUT -j DROP" ... then spending a while starting at a disconnected terminal wondering what happened. – Kickaha Aug 9 '17 at 13:22
  • I think it can be done in one command: sudo restart ssh. service ssh restart does not work in my Ubuntu 14.04. – chus Jul 2 '18 at 13:12

protected by Community May 15 '15 at 15:56

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.