Automatically Start SSH Server on Boot

For some reason, the SSH server is not starting on boot. I have to manually start it using the this command:

sudo service ssh start

I haven’t modified anything related to the ssh configuration. How do I get it to start automatically on boot?

sudo systemctl enable sshd.service
1 Like

When I try that command I get this error:

raspberrypi:~$ sudo systemctl enable sshd.service
Failed to execute operation: No such file or directory

1 Like

May I ask:

  • What version of Ubuntu MATE you’re using?
  • How did you setup SSH?
1 Like

Sure.
Version 16.04.2 LTS
I haven’t modified ssh yet at all since install.

1 Like

Are you sure you actually installed it?
It's not done by default.

1 Like

Yeah, I’ve done apt-get install openssh-server and can confirm it’s installed. It came with mate.

1 Like

My apologies, didn’t notice this was in Raspberry Pi area. I assumed UM on Raspberry Pi uses systemd as well. Looks like that’s not the case. You can check, of course:

sudo stat /proc/1/exe -c ' File: %N'

should tell you what init system is in use. Reply should be one of the three:

File: '/proc/1/exe' -> '/lib/systemd/systemd'
File: '/proc/1/exe' -> '/sbin/init'
File: '/proc/1/exe' -> '/sbin/upstart'

Since you can start the service manually with service command, it’s either sysvinit or Upstart (which can run syvinit scripts as well - so it’s a bit confusing). Assuming your system is using Upstart you could try:

sudo update-rc.d ssh defaults

and then reboot.

1 Like

The output is actually the first one…

‘/lib/systemd/systemd’

1 Like

Can you please provide the output of the command:

ps axu | grep [s]sh

1 Like

[email protected]:~$ ps axu | grep [s]sh
andy 1199 0.0 0.0 3000 216 ? Ss 11:48 0:00 /usr/bin/ssh-agent -s

1 Like

Thanks, how about:

ls -alh /etc/ssh/sshd_config

1 Like

That’s really odd. Installing openssh-server package should install the systemd unit file (/lib/systemd/system/ssh.service) and the necessary config files. Vendor default is “enabled” so it’s (or should be) just a question of installing the package and you’re good to go.

If systemctl status sshd.service gives you this error as well, then I guess the lazy man’s solution is to simply re-install openssh-server, preferably in terminal with apt-get so you get to see possible errors.

Please let us know how it goes. I’m off for a couple of hours but will check this thread when I come back (and there are others here to help you).

1 Like

Output:

[email protected]:~$ ls -alh /etc/ssh/sshd_config
-rw-r–r-- 1 root root 2.5K Feb 11 13:21 /etc/ssh/sshd_config

1 Like

I’ve removed openssh-server and reinstalled it with no luck.

sudo apt-get remove openssh-server
sudo apt-get install openssh-server

I still get the No such file or directory error.

[email protected]:~$ sudo systemctl status sshd.service
● sshd.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)

1 Like

Can you please remove again then use:

sudo apt install ssh

1 Like

Ok, something just occured to me. Can you please try with ssh.service, not sshd.service:

sudo systemctl status ssh.service

This, of course, with openssh-server package installed. Also, what is the output of:

ls -la /etc/systemd/system/ssh*.service

Explanation: the unit file in /lib/systemd/system is ssh.service, not sshd.service. It does contain directive Alias=sshd.service, but I noticed that doesn’t necessarily work if the symbolic link in /etc/systemd/system is ssh.service, not sshd.service.

Old dogs like me automatically think “with D”, since it’s a daemon, not a client we are talking about here.

If you got status with ssh.service, you can use that to enable ssh daemon at boot:

sudo systemctl enable ssh.service
7 Likes

Thanks, this fixed it for me.

1 Like

Good afternoon all,

I have installed UBUNTU Mate on my RasPi 3 with WiFi and working relatively fine, relatively is because I cannot connect to the server via SSH (yes SSH is enabled) unless I physically logged ito the server, which is not at all convenient, it is a bit of a leg work going up the stairs when rebooting etc.

Is there any way that the configuration files execute automatically after reboot please without logging in? I am trying to use it as VPN Server if it does not load the configuration files then VPN Server cannot work at all. (I have installed VPN Server on UBUNTU somewhere else and it works fine).

Cheers
Siamak

1 Like

I’ve never encountered this problem - possibly because I have my system set to login automatically on boot, so the circumstances don’t occur.
Derek