Score:0

Cannot enable ssh service on Ubuntu 20.04

td flag

I am trying to remote connet my desktop(Ubuntu 20.04.2 LTS) via MacBook. But my request is rejected. So I check my ssh status on Ubuntu.

sightvanish@SVPC:~$ sudo systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: enabled)
     Active: inactive (dead)
       Docs: man:sshd(8)
             man:sshd_config(5)

It shows ssh service is inactive. Then I try to enable it manually.

/etc/init.d/ssh start
Starting ssh (via systemctl): ssh.serviceJob for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.
 failed!

So I do what it says.

sightvanish@SVPC:~$ systemctl status ssh.service
● ssh.service - OpenBSD Secure Shell server
     Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2021-09-10 11:38:27 CST; 21min ago
       Docs: man:sshd(8)
             man:sshd_config(5)
    Process: 13329 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=1/FAILURE)

9月 10 11:38:27 SVPC systemd[1]: ssh.service: Scheduled restart job, restart counter is at 5.
9月 10 11:38:27 SVPC systemd[1]: Stopped OpenBSD Secure Shell server.
9月 10 11:38:27 SVPC systemd[1]: ssh.service: Start request repeated too quickly.
9月 10 11:38:27 SVPC systemd[1]: ssh.service: Failed with result 'exit-code'.
9月 10 11:38:27 SVPC systemd[1]: Failed to start OpenBSD Secure Shell server.

Then I check it,

sightvanish@SVPC:~$ sshd -t
/etc/ssh/sshd_config line 5: Deprecated option ServerKeyBits
/etc/ssh/sshd_config line 7: Deprecated option KeyRegenerationInterval
/etc/ssh/sshd_config line 16: Deprecated option RhostsAuthentication
/etc/ssh/sshd_config line 17: Deprecated option RhostsRSAAuthentication
/etc/ssh/sshd_config line 18: Deprecated option RSAAuthentication
Unable to load host key: /etc/ssh/ssh_host_key
sshd: no hostkeys available -- exiting.

Well, I generate new key sudo ssh-keygen -A But I still cannot enable ssh service.

sightvanish@SVPC:/etc/ssh$ sudo service ssh start
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.

I am really confused. Please help me!

in flag
A couple of questions: (1) have you connected to this computer in the past over SSH? (2) have you verified that `ufw` is allowing the connection?
Wayne Vosberg avatar
bd flag
for `sshd -t`, try `sudo sshd -t`. Host keys in /etc/ssh should only be readable by root. Then try `sudo /usr/sbin/sshd -ddd` -- this will output a lot of debug messages.
Wayne Vosberg avatar
bd flag
could also try `sudo systemctl reset-failed sshd` , `sudo systemctl enable sshd` , `sudo systemctl start sshd`
raj avatar
cn flag
raj
If all else fails, I guess that purging the `openssh-server` package (purging, to remove all configuration), then optionally removing `sshd_config` and all `ssh_host_*_key*` files from `/etc/ssh` (if they are left there) then reinstalling it (which should install the default config and generate new host keys from scratch) should help.
pa4080 avatar
cn flag
Does this answer your question? [SSH Server stops working after reboot, caused by missing /var/run/sshd](https://askubuntu.com/questions/1109934/ssh-server-stops-working-after-reboot-caused-by-missing-var-run-sshd)
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.