0

I disable the ssh server with systemctl disable ssh then reboot. After reboot, I still can log into the remote server through ssh. I use systemctl status ssh to check the server status and it is inactive.

$ systemctl -a | grep ssh
ssh.service                                               loaded    inactive dead      OpenBSD Secure Shell server
ssh@3-192.168.0.120:22-192.168.0.104:31079.service        loaded    active   running   OpenBSD Secure Shell server per-connection daemon (192.168.0.104:31079)
system-ssh.slice                                          loaded    active   active    system-ssh.slice
ssh.socket                                                loaded    active   listening OpenBSD Secure Shell server socket

How can I truly shut down ssh server?

  • You can simply uninstall openssh-server. – FedonKadifeli Jul 9 '19 at 11:33
  • You seem to have more SSH-stuff installed than on average Ubuntu (checked my two Ubuntu 18.04 installation and got only the ssh.service line). Disable/uninstall what you don’t need. – Melebius Jul 9 '19 at 11:44
  • 1
    Disable and stop the ssh.socket unit. It is used for socket-activated sshd. – PerlDuck Jul 9 '19 at 12:06
  • FYI: disable on its own doesn't stop the running process ;) you still need to disable the socket and stop the service. As was stated in other answers. – Thomas Ward Jul 9 '19 at 16:00
2

You can stop a service with systemctl, but you need to also disable it and anything that would cause it to start up. You can use systemctl disable sshd so that sshd will not be started when you turn the system on in the future. If I'm not mistaken, any existing ssh connections will be maintained even after running systemctl stop sshd. No new connections should be able to become established.

You can see that with your systemctl command, you have sshd.service and sshd.socket. You need to stop and disable both of these using systemctl, likely the socket first, and then the service. One is dependent on the other and will not be disabled unless done in the proper order.

$ sudo systemctl stop sshd.service sshd.socket
$ sudo systemctl disable sshd.socket
$ sudo systemctl disable sshd.service

As it has been mentioned, Ubuntu's openssh-server only installs ssh.service, and no socket. This is also true about Debian Stretch. It seems you've deviated from default and without more details it's hard to know exactly what's going on.

Depending on the requirements, removing the package providing sshd (openssh-server) would be a more fool-proof approach. Please consider things such as the physical location of the machine, etc, before completely disabling sshd .

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.