Error enabling sshd on Ubuntu 16.04

I just installed Ubuntu Server 16.04 on a virtual machine and then installed openssh-server. When I tried to enable sshd:

systemctl enable sshd.service

I got this message:

Failed to execute operation: Too many levels of symbolic links

Does anyone know what this is? Did I forget to do something?


Solution 1:

That's because the service name is actually ssh.service, not sshd.service.

Do this instead:

systemctl enable ssh.service

Explanation

When you install openssh-server, the service is automatically enabled in systemd. During the enabling process, a symbolic link for an enabled sshd.service is also created. This symbolic link goes away if you do systemctl disable ssh.service or systemctl disable sshd.service.

You can see the symbolic link is reportedly created here:

root@node51 [~]# systemctl enable ssh.service
Synchronizing state of ssh.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable ssh
Created symlink from /etc/systemd/system/sshd.service to /lib/systemd/system/ssh.service.

Because of systemd's design, systemd will not enable a service that is a symbolic link.
This is discussed on Red Hat Bugzilla.