Best way to disable SSH for all users?

For security reasons I want to turn off SSH when I don’t use it and turn it on again via a VNC connection as I can connect to my web server remotely over the Digitalocean control panel’s console instead, and turn on SSH that way.

Is below the best way of doing it?

sudo stop ssh
sudo ufw deny 22

And turn on SSH via VNC

sudo ufw allow 22/tcp
sudo start ssh 

Or should I use any of the below variants?

sudo service ssh stop
sudo systemctl stop ssh
sudo /etc/init.d/ssh stop

I’m on a UBUNTU 16.04 LTS server. And I want to disable SSH for all users, not only for root.


Why would you do that? It’s way more elegant to harden your SSH. Few tips:

  • dont use root for ssh
  • set AllowUsers directive and list your account in there – that way only you will be allowed to ssh
  • create a 4096 bit rsa key (or 512 ecdsa), don’t use password authentication for your ssh session
  • set up a firewall rule to allow incoming connections on port 22 only from your ip address

Source : Link , Question Author : Gabriel , Answer Author : 13dimitar

Leave a Comment