Best way to disable SSH for all users?
Ubuntu 16.04 LTS uses systemd, which means you want systemctl
.
To prevent the service from starting automatically at boot time, use
sudo systemctl disable ssh.service
To stop currently running one, use
sudo systemctl stop ssh.service
and
sudo systemctl start ssh.service
Note that this stops ssh
server. You can still use ssh
client to connect to remote hosts, but with ssh
server disabled remote connections destined to your machine will be disabled
If you want to completely disable the service/unit, use
sudo systemctl mask ssh.service
The above makes systemd unit files a symlink to /dev/null
, so any start attempts will fail
Related videos on Youtube
Gabriel
Front-end Developer/UX/Interaction Designer of hybrid apps/PWAs/responsive Web with focus on HTML5, CSS3, LESS, SASS, WordPress, and JavaScript frameworks like Angular, Ionic, Bootstrap, Zurb Foundation, Kendo UI Data visualizations, and Material Design. As both a Front-end Developer and Interaction Designer, I can identify more possibilities in user interface design and solution architecture. Your project gets on-track faster, and at a price that will make you smile. I deliver rapid prototyping with Angular/HTML5 from Adobe XD/Photoshop/Sketch mockups to Web or hybrid apps. I’m also experienced in integration to .NET MVC, WordPress PHP MVC, backend Rest APIs, payment gateways via JSON; and ID/authentication services like BankID. I focus primarily on responsive Web, PWAs and hybrid mobile apps, placing an emphasis on optimization of sales flows, speed/SEO optimization, QA/testing, Web security and a more effective interactive communication. Check-out my portfolio site at http://angular-developer.com/ I'm fluent in English, French and Swedish (mother tongue), and understand some German, Italian, Norwegian, and Danish. Currently taking a university part-time course in IoT with Arduino/Android. I also have extensive knowledge in blockchains and cryptocurrencies.
Updated on September 18, 2022Comments
-
Gabriel over 1 year
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.
-
smw over 7 yearsI'm not sure I understand your rationale here - AFAIK VNC is much less secure than SSH (unless the VNC is tunneled... over SSH)
-
Gabriel over 7 years@muru It was only here I got a relevant answer though... by Serge
-