108

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.

1
  • post the output of ls /etc/init.d | grep ssh Commented May 5, 2014 at 3:49

2 Answers 2

171

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.

5
  • 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
    Commented Dec 30, 2015 at 9:30
  • 4
    The first part of the answer still applies. Also note it should be sudo service ssh restart Commented Jan 22, 2017 at 20:25
  • 'sudo service ssh restart' works fine on ubuntu xenial. Commented May 26, 2018 at 6:39
  • works for ubuntu 1404
    – bronze man
    Commented Oct 30, 2019 at 8:23
  • 1
    @JdeBP why did you link to an answer dealing with how to disable the autostart of SSHD, rather than dealing with how to restart SSHD?
    – red-o-alf
    Commented Mar 14, 2020 at 1:25
3

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

3
  • 26
    this is really bad for remote servers, you can log yourself out with that first command and it's not automatically restarted. Commented Aug 23, 2016 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
    Commented Aug 9, 2017 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
    Commented Jul 2, 2018 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .