Report this

What is the reason for this report?

prevent firewall ssh lock out

Posted on August 4, 2025

To secure my droplets, for ssh I usually replace text password with public key and change 22 to a non standard port. In adjusting my firewall settings I’ve managed to get locked out of my own account. The emergency recovery console has saved me. In order to prevent getting locked out, what does Digital Ocean require - port 22? Text passwords?

In a related question - /etc/ssh/sshd_config.d has two files: 50-cloud-init.conf 60-cloudimg-settings.conf regarding text passwords, one says yes, the other no. Can you explain this? TIA



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
0

Accepted Answer

Heya, @enews

The recovery console does not use the SSH protocol, and you can always use it in case you get locked out because of firewall management.

You can use the DigitalOcean Cloud Firewall or UFW to allow only certain IPs on the SSH Port.

You can verify what’s active by running:

sshd -T | grep passwordauthentication

This will show you what the final active value is after the includes are applied.

Hope that this helps!

Have you tested your SSH config changes before disconnecting? Running sshd -t checks syntax, and sshd -T shows effective config. The conflicting password settings come from cloud-init managing defaults sometimes multiple files exist, but only the last applies.

Check the firewall shown on the Digital Ocean web page for your Droplet. It’s a firewall at the virtual level. Traffic hits it before anything on your server.

Digital Ocean / click your droplet / Networking / scroll down to Firewalls.

Here you can create or modify a named firewall.

Edit the firewall and add a new rule: Custom, TCP, and the new port number.

Maybe leave the existing rule SSH, TCP, 22. Deleting it I think caused me problems.

As for /etc/ssh/sshd_config.d, anything file in that directory is included by /etc/ssh/sshd_config. You can see the line in sshd_config that includes files from that directory. The files in there on a new droplet are mods put in by DO, and/or by whatever Linux distrib you’re using. They’re good.

Best practice is to mod your port by creating your own file in that directory, instead of editing sshd_config. Otherwise upgrades to sshd or the system may wipe out your mods.

Create your own file like 90-my-mods.conf. The number in the name is the order in which it will be processed; you want it last, generally. Put in that file the one line for the Port… new number. Restart the service, and do the other steps in whatever tutorial you’re using, like new firewall rules within your server. In my case, Fedora, /etc/ssh/sshd_config had a comment telling to me to do an SELinux thing, which matched tutorials on Fedora.

It took days for me to remember there was a virtual-level firewall outside the server!

As for recovery, I save a snapshot and restore if needed, but then I found out if you keep your ssh window open, you can open a second one with the new port, and the old one will keep running, so you can undo whatever you did if the new port doesn’t work. There’s also a more sophisticated way that covers the case where you lose your network connection in the middle of all this, but snapshot/restore is good enough for me.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.