- cross-posted to:
- linux@programming.dev
- cross-posted to:
- linux@programming.dev
When you spin up a fresh public Linux instance, automated scanners start knocking on your doors within milliseconds.
It doesn’t take much to get locked down properly, but missing a few basics can leave you exposed.
I’ve put together a straightforward guide covering the essential hardening steps from UFW and SSH key-only auth to secure Docker bindings and automated maintenance.
Original content by The Unknown Universe, written by a human and not AI generated!



I really appreciate the effort but… how to say it?.. it might be useful to make sure you understand a topic before trying to teach it to others :)
Some notes:
Not as important as most people think (local privilege escalation is a thing, and it’s also quite easy for your user to alias sudo to something that will capture your password the next time you type it).
Basically: if an hostile actor gets a shell on your server, you are fucked anyway.
This is the same as being root. Yep, the very same thing you went that whole length to avoid :)
Look into unattended upgrades. Also… it’s not automation if you have to run a script manually :)
I keep telling EVERYONE this, and we continue to get “findings” around privilege escalation.
Not today, satan.
Passwordless root allows you to require another factor of authentication on the off chance you didn’t set up key only ssh login like the top of the guide says. That second factor is the administrator account name. Now you can make this as generic as you want but assuming your non root admin account isn’t named “administrator” or “admin” then you just increased the security of your system.
Suggesting that because privilege escalation exists there is no difference between a user and root is absurd on the face of it. Privesc requires vulnerable versions of vulnerable packages with the specific circumstances present that allow pre and post exploitation actions. In case you were operating under the assumption that most privesc goes from local administrator to root, usually you’re going from some relatively unprivileged user account that handles a service up to root and that’s harder than just invoking sudo.
You would still want to roll over your credentials and restore from backups but “safe cracking tools exist so just leave the cash register deposits in plain view on a shelf behind the desk” isn’t a strong argument for password root.
E: @talkingpumpkin@lemmy.world correctly pointed out that a nonstandard admin account name isn’t a second factor. It’s more like an additional secret.
A “secret” administrator account name is not a second authentication factor: it’s just another “something you know”, basically the same as using a slightly longer password.
On top of that, account names are generally not treated with the same confidentiality passwords or private keys are treated with: while you can trust that software and collaborators will not leak a password or private key, you cannot make the same assumption about usernames.
Yeah that was a bad choice of words on my part.
Consider though that everything I handle with a public facing ip gets 69 million attempts to login as “root”, “admin”, “docker” and everything else under the sun but not even once has someone tried to login as my admin user. It’s acting as more than a slightly longer password.
It’s nice that your system has layers, but when the cutworms get on your onion they can still spoil the whole thing.
Sure, onions can go all the way bad. I’d rather put my special thing inside an onion than an apple.
Apples, Onions, Chocolate Mousse, I’d rather have any of them inside a bomb-proof safe.
I’m gonna go out on a limb here and liken the encrypted shell access that requires an additional secret just to have one’s password considered closer to the bombproof safe than to a food item.
A metaphor is nice but actually completing it is what puts it above mere allusion.
I’m gonna go out on a limb here and liken the encrypted shell access that requires an additional secret to two secrets written on a sticky note instead of one…
Are you now making an argument against password ssh or against obscurity altogether?
If it’s the former I’m on your side. Key ssh with passwords turned off defeated the recent asterisk mess if anyone was unfortunate enough to be relying on musl ssh.
Sorry, that last comment was rushed and just reacting to the philosophy of “let’s just throw another password around it.”
My real/main point is about root (sudo) access vs “unprivileged” users. In my experience, sudo is like putting up a (thin) glass window on a house, it’s a great way to communicate to gentle-folk that they are not supposed to come in, the door is locked, but they can still look inside (read access), and if they don’t mind making a mess they can certainly smash the window to bypass the lock, or if the window is too strong for them to break they can more easily burn the whole house down. A sudo locked door might make it necessary to have unusual lock picking skills if you’re going to sneak in, rearrange the furniture, then leave without everyone knowing that things have been messed with on first glance, but it’s not going to stop a DDOS from succeeding. The typical “non-privileged” user with command line access can easily trash most systems into a non-functional state, shortly after exporting most data of any value.
Then (different, but related rant): all of the “physical access to the device required” attack hardenings are of little help preventing these kind of attacks: https://www.infosecinstitute.com/resources/general-security/usb-killer-how-to-protect-your-devices/
Systems need good physical security first, and then they need serious least-privilege protection against ALL users, not just those who can get root access. Access to a general purpose terminal, even without root privilege, is more privilege than any untrusted user should ever have.
Exactly, you shouldnt add your user to Docker and you should run your Docker containers as your user or another limited user rather than the default root.
Be very selective with whether you expose your docker socket to any container. I just give Beszel Read Only. Gives me container perfs and flags updates.
For the update script, you can just make it a cron job. Id add that to the guide. A daily update and weekly backup cron job is my setup.
Use podman instead, it doesn’t need root. And putting the docker socket in ro mode doesn’t help at all, because ro is for files, while this here is a connection.
Yeah, I’m evaluating moving to it, or just running everything baremetal or in jails from FreeBSD. Slowly moving away from Linux in general.
Of course privilege escalation exists, but why roll out the red carpet on an attacker that managed to get shell access? Maybe in the time that they take to figure out that privilege escalation you have the time to detect the attack and defend against them
Most shell users have enough privilege to read (exfiltrate) most data-value from a server, and they almost always have the capacity to damage it beyond functional operation.
If someone put a script on your server that tried to do privilege escalation you should just assume it was successful and act accordingly. It doesn’t really change what should happen.
replacing or reimaging it automatically when you see something like this feels like overkill.
Only if you haven’t built the infrastructure to make that trivial, which you should have. If you have any data worth securing it’s not even close to overkill.
I like write filters -> mostly immutable systems. SHTF? reboot ASAP.
No root but then they use sudo? That’s going out from the frying pan into the fire.
sudo is a great tool, for people who play nicely.
It’s like a lock on a glass door, with a rock garden outside.