Cannot restart SSH daemon after changing sshd_config to port 2222

64,266

Solution 1

As @techraf said, most likely you made a simple mistake in your /etc/ssh/sshd_config. Try sshd test mode:

$ sudo sshd -t
/etc/ssh/sshd_config: line 1: Bad configuration option: sds

From man page:

  • -t Test mode. Only check the validity of the configuration file and sanity of the keys. This is useful for updating sshd reliably as configuration options may change.
  • -T Extended test mode. Check the validity of the configuration file, output the effective configuration to stdout and then exit. Optionally, Match rules may be applied by specifying the connection parameters using one or more -C options.

Solution 2

Are you running on a system that utilizes SELinux? It could be that this is denying the port bind; try adding in a new rule.

semanage port -a -t ssh_port_t -p tcp 2222
Share:
64,266

Related videos on Youtube

FullStack
Author by

FullStack

Updated on September 18, 2022

Comments

  • FullStack
    FullStack over 1 year

    I have been looking around and couldn't find a solution to the issue I am having. I am running Ubuntu 16.04 LTS, and I followed instructions on the Ubuntu page for changing the SSH port to 2222 by updating the sshd_config file.

    # What ports, IPs and protocols we listen for
    Port 2222
    

    When I execute the command sudo systemctl restart sshd.service, however, I only get the following error:

    Job for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.
    

    I then executed the command systemctl status ssh.service and got

    ● ssh.service - OpenBSD Secure Shell server
       Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Wed 2016-09-07 23:24:04 EDT; 1min 28s ago
      Process: 16813 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
     Main PID: 16813 (code=exited, status=255)
    
    Sep 07 23:24:04 sys-0 systemd[1]: Starting OpenBSD Secure Shell server...
    Sep 07 23:24:04 sys-0 systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
    Sep 07 23:24:04 sys-0 systemd[1]: Failed to start OpenBSD Secure Shell server.
    Sep 07 23:24:04 sys-0 systemd[1]: ssh.service: Unit entered failed state.
    Sep 07 23:24:04 sys-0 systemd[1]: ssh.service: Failed with result 'exit-code'.
    

    What does the error mean, and how can I address it?

    • techraf
      techraf over 7 years
      Most likely you made a simple mistake in your sshd_config. What if you put back the original one?
    • Paul
      Paul over 7 years
      sudo sshd -vvvf /etc/ssh/sshd_config should give you clue as to what is wrong
    • FullStack
      FullStack over 7 years
      When I put back the original one, it works as usual. However, port 2222 worked for me today doing the exact same thing I did last night. Very odd.
    • FullStack
      FullStack over 7 years
      @techraf I deleted the other one. I'm never sure which SE is better for this type of question
    • Pablo A
      Pablo A about 6 years
      @Paul on openssh-server 1:7.4p1-10+deb9u2 on Debian 9 I get unknown option -- v.
  • FullStack
    FullStack over 7 years
    no, I am not running on SELinux, but somehow this morning doing the same things worked. Thanks so much for your input
  • Sayali
    Sayali over 5 years
    Still the same error, nothing has changed
  • HugoWeb
    HugoWeb about 5 years
    Thanks this helped me!
  • KansaiRobot
    KansaiRobot almost 4 years
    this helped me a lot!
  • HorstKevin
    HorstKevin over 3 years
    How is this related to the question?