Background: 15 years of experience in software and apparently spoiled because it was already set up correctly.

Been practicing doing my own servers, published a test site and 24 hours later, root was compromised.

Rolled back to the backup before I made it public and now I have a security checklist.

top 50 comments

sorted by: hot top controversial new old
[–] 177 points 2 years ago (1 child)

Basic setup for me is scripted on a new system. In regards to ssh, I make sure:

  • Root account is disabled, sudo only
  • ssh only by keys
  • sshd blocks all users but a few, via AllowUsers
  • All 'default usernames' are removed, like ec2-user or ubuntu for AWS ec2 systems
  • The default ssh port moved if ssh has to be exposed to the Internet. No, this doesn't make it "more secure" but damn, it reduces the script denials in my system logs, fight me.
  • Services are only allowed connections by an allow list of IPs or subnets. Internal, when possible.

My systems are not "unhackable" but not low-hanging fruit, either. I assume everything I have out there can be hacked by someone SUPER determined, and have a vector of protection to mitigate backwash in case they gain full access.

  • source
  • hideshow 2 child comments
  • [–] 74 points 2 years ago (4 children)
    • The default ssh port moved if ssh has to be exposed to the Internet. No, this doesn't make it "more secure" but damn, it reduces the script denials in my system logs, fight me.

    Gosh I get unreasonably frustrated when someone says yeah but that's just security through obscurity. Like yeah, we all know what nmap is, a persistent threat will just look at all 65535 and figure out where ssh is listening.. But if you change your threat model and talk about bots? Logs are much cleaner and moving ports gets rid of a lot of traffic. Obviously so does enabling keys only.

    Also does anyone still port knock these days?

  • source
  • parent
  • hideshow 5 child comments
  • load more comments (3 replies)
  • [–] 78 points 2 years ago (1 child)

    One time, I didn’t realize I had allowed all users to log in via ssh, and I had a user β€œsteam” whose password was just β€œsteam”.

    β€œHey, why is this Valheim server running like shit?”

    β€œWtf is xrx?”

    β€œOh, it looks like it’s mining crypto. Cool. Welp, gotta nuke this whole box now.”

    So anyway, now I use NixOS.

  • source
  • hideshow 2 child comments
  • [–] 52 points 2 years ago (1 child)

    Interesting. Do you know how it got compromised?

  • source
  • hideshow 2 child comments
  • [–] [S] 73 points 2 years ago* (17 children)

    I published it to the internet and the next day, I couldn't ssh into the server anymore with my user account and something was off.

    Tried root + password, also failed.

    Immediately facepalmed because the password was the generic 8 characters and there was no fail2ban to stop guessing.

  • source
  • parent
  • hideshow 19 child comments
  • [+] 96 points 2 years ago* (last edited 1 year ago) (1 child)
  • [–] 53 points 2 years ago* (4 children)

    More importantly, don't open up SSH to public access. Use a VPN connection to the server. This is really easy to do with Netbird, Tailscale, etc. You should only ever be able to connect to SSH privately, never over the public net.

  • source
  • parent
  • hideshow 5 child comments
  • load more comments (3 replies)
  • [–] 30 points 2 years ago (6 children)

    wow crazy that this was the default setup. It should really force you to either disable root or set a proper password (or warn you)

  • source
  • parent
  • hideshow 7 child comments
  • load more comments (5 replies)
  • load more comments (15 replies)
  • [–] 48 points 2 years ago (1 child)

    Lol you can actually demo a github compromise in real time to an audience.

    Make a repo with an API key, publish it, and literally just watch as it takes only a few minutes before a script logs in.

  • source
  • hideshow 2 child comments
  • [–] 31 points 2 years ago (2 children)

    I search commits for "removed env file" to hopefully catch people who don't know how git works.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 15 points 2 years ago* (3 children)

    --verbose please?

    edit: never mind, found it. So there's dumbasses storing sensitive data (keys!) inside their git folder and unable to configure .gitignore...

  • source
  • parent
  • hideshow 4 child comments
  • load more comments (2 replies)
  • load more comments (1 reply)
  • [–] 48 points 2 years ago (1 child)

    I've gotta say this post made me appreciate switching to lemmy. This post is actually helpful for the poor sap that didn't know better, instead of pure salt like another site I won't mention.

  • source
  • hideshow 2 child comments
  • [–] [S] 33 points 2 years ago (1 child)

    I shared it because, out there, there is a junior engineer experiencing severe imposter syndrome. And here I am, someone who has successfully delivered applications with millions of users and advanced to leadership roles within the tech industry, who overlook basic security principles.

    We all make mistakes!

  • source
  • parent
  • hideshow 2 child comments
  • [–] 43 points 2 years ago (3 children)

    Do not allow username/password login for ssh. Force certificate authentication only!

  • source
  • hideshow 4 child comments
  • [–] 12 points 2 years ago (2 children)

    If it's public facing, how about dont turn on ssh to the public, open it to select ips or ranges. Use a non standard port, use a cert or even a radius with TOTP like privacyIdea. How about a port knocker to open the non standard port as well. Autoban to lock out source ips.

    That's just off the top of my head.

    There's a lot you can do to harden a host.

  • source
  • parent
  • hideshow 2 child comments
  • load more comments (2 replies)
  • load more comments (2 replies)
    [–] 40 points 2 years ago (5 children)

    How are people's servers getting compromised? I'm no security expert (I've never worked in tech at all) and have a public VPS, never been compromised. Mainly just use SSH keys not passwords, I don't do anything too crazy. Like if you have open SSH on port 22 with root login enabled and your root password is password123 then maybe but I'm surprised I've never been pwned if it's so easy to get got...

  • source
  • hideshow 7 child comments
  • load more comments (3 replies)
    [–] 34 points 2 years ago (2 children)

    As a linux n00b who just recently took the plunge and set up a public site (tho really just for my own / selfhosting),

    Can anyone recommend a good guide or starting place for how to harden the setup? Im running mint on my former gaming rig, site is set up LAMP

  • source
  • hideshow 4 child comments
  • [–] 29 points 2 years ago (4 children)

    The other poster gave you a lot. If that's too much at once, the really low hanging fruit you want to start with is:

    • Choose an active, secure distro. There's a lot of flavors of Linux out there and they can be fun to try but if you're putting something up publicly it should be running on one that's well maintained and known for security. CentOS and Debian are excellent easy choices for example.

    • Similarly, pick well maintained software with a track record. Nginx and Apache have been around forever and have excellent track records, for example, both for being secure and fixing flaws quickly.

    • If you use Docker, once again keep an eye out for things that are actively maintained. If you decide to use Nginx, there will be five million containers to choose from. DockerHub gives you the tools to make this determination: Download number is a decent proxy for "how many people are using this" and the list of updates tells you how often and how recently it's being updated.

    • Finally, definitely do look at the other poster's notes about SSH. 5 seconds after you put up an SSH server, you'll be getting hit with rogue login attempts.

    • Definitely get a password manager, and it's not just one password per server but one password per service. Your login password to the computer is different from your login to any other things your server is running.

    The rest requires research, but these steps will protect you from the most common threats pretty effectively. The world is full of bots poking at every service they can find, so keeping them out is crucial. You won't be protected from a dedicated, knowledgeable attacker until you do the rest of what the other poster said, and then some, so try not to make too many enemies.

  • source
  • parent
  • hideshow 4 child comments
  • load more comments (4 replies)
  • [–] 25 points 2 years ago* (last edited 2 years ago) (1 child)

    Paranoid external security. I'm assuming you already have a domain name. I'm also assuming you have some ICANN anonymization setup.

    This is your local reverse Proxy. You can manage all this with a container called nginx proxy manager, but it could benefit you to know it's inner workings first. https://www.howtogeek.com/devops/what-is-a-reverse-proxy-and-how-does-it-work/

    https://cloud9sc.com/nginx-proxy-manager-hardening/

    https://github.com/NginxProxyManager/nginx-proxy-manager

    Next you'll want to proxy your IP address as you don't want that pointing to your home address

    https://developers.cloudflare.com/learning-paths/get-started-free/onboarding/proxy-dns-records/

    Remote access is next. I would suggest setting up wireguard on a machine that's not your webserver, but you can also set that up in a container as well. Either way you'll need to punch another hole in your router to point to your wire guard bastion host on your local network. It has many clients for windows and linux and android and IOS

    https://github.com/angristan/wireguard-install

    https://www.wireguard.com/quickstart/

    https://github.com/linuxserver/docker-wireguard

    Now internally, I'm assuming you're using Linux. In that case I'd suggest securing your ssh on all machines that you log into. On the machines you're running you should also install fail2ban, UFW, git, and some monitoring if you have the overhead but the monitoring part is outside of the purview of this comment. If you're using UFW your very first command should be sudo ufw allow ssh

    https://www.howtogeek.com/443156/the-best-ways-to-secure-your-ssh-server/

    https://github.com/fail2ban/fail2ban

    https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands

    Now for securing internal linux harden the kernel and remove root user. If you do this you should have a password manager setup. keepassx or bitwarden are ones I like. If those suck I'm sure someone will suggest something better. The password manager will have the root password for all of your Linux machines and they should be different passwords.

    https://www.makeuseof.com/ways-improve-linux-user-account-security/

    https://bitwarden.com/help/self-host-an-organization/

    https://keepass.info/

    Finally you can harden the kernel

    https://codezup.com/the-ultimate-guide-to-hardening-your-linux-system-with-kernel-parameters/

    TLDR: it takes research but a good place to start is here

    https://www.digitalocean.com/community/tutorials/recommended-security-measures-to-protect-your-servers

  • source
  • parent
  • hideshow 2 child comments
  • [–] 29 points 2 years ago (2 children)

    I'm confused. I never disable root user and never got hacked.

    Is the issue that the app is coded in a shitty way maybe ?

  • source
  • hideshow 3 child comments
  • [–] 25 points 2 years ago (2 children)

    You can't really disable the root user. You can make it so they can't login remotely, which is highly suggested.

  • source
  • parent
  • hideshow 3 child comments
  • [–] 12 points 2 years ago (1 child)
    sudo passwd -l root
    

    This disables the root user

  • source
  • parent
  • hideshow 2 child comments
  • load more comments (1 reply)
  • load more comments (1 reply)
    [–] 26 points 2 years ago* (5 children)

    You should turn off ssh password logins on external facing servers at a minimum. Only use ssh keys, install fail2ban, disable ssh root logins, and make sure you have a firewall limiting ports to ssh and https.

    This will catch most scripted login attempts.

    If you want something more advanced, look into https://en.m.wikipedia.org/wiki/Security_Technical_Implementation_Guide and try to find an ansible playbook to apply them.

  • source
  • hideshow 5 child comments
  • load more comments (5 replies)
    [–] 26 points 2 years ago* (last edited 2 years ago) (6 children)

    I can’t even figure out how to expose my services to the internet, honestly it’s probably for the best Wireguard gets the job done in the end.

  • source
  • hideshow 6 child comments
  • load more comments (6 replies)

    This sounds like something everyone should go through at least once, to underscore the importance of hardening that can be easily taken for granted

  • source
  • [–] 25 points 2 years ago* (2 children)

    And this is why every time a developer asks me for shell access to any of the deployment servers, I flat out deny the request.

    Good on you for learning from your mistakes, but a perfect example for why I only let sysadmins into the systems.

  • source
  • hideshow 3 child comments
  • load more comments (1 reply)
    [–] 22 points 2 years ago (6 children)

    Permitting inbound SSH attempts, but disallowing actual logins, is an effective strategy to identify compromised hosts in real-time.

    The origin address of any login attempt is betraying it shouldn’t be trusted, and be fed into tarpits and block lists.

  • source
  • hideshow 6 child comments
  • load more comments (6 replies)
    [–] 21 points 2 years ago (2 children)

    Had this years ago except it was a dumbass contractor where I worked who left a Windows server with FTP services exposed to the Internet and IIRC anonymous FTP enabled, on a Friday.

    When I came in on Monday it had become a repository for warez, malware, and questionable porn. We wiped out rather than trying to recover anything.

  • source
  • hideshow 2 child comments
  • load more comments (2 replies)
    [–] 20 points 2 years ago (1 child)
    [–] 18 points 2 years ago

    I'm having the opposite problem right now. Tightend a VM down so hard that now I can't get into it.

  • source
  • [–] 17 points 2 years ago* (2 children)

    On a new linux install or image I will always:

    • Make new users(s)
    • Setup new user to sudo
    • Change ssh port
    • Change new user to authenticate ssh via key+password
    • Disable root ssh login
  • source
  • hideshow 2 child comments
  • load more comments (2 replies)
    [–] 15 points 2 years ago (4 children)

    I've been quite stupid with this but never really had issues. Ever since I changed the open ssh port from 22 to something else, my server is basically ignored by botnets. These days I obviously also have some other tricks like fail2ban, but it was funny how effective that was.

  • source
  • hideshow 4 child comments
  • load more comments (4 replies)
    [–] 15 points 2 years ago (3 children)

    Although disabling the root user is a good part of security, leaving it enabled should not alone cause you to get compromised. If it did, you were either running a very old version of OpenSSH with a known flaw, or, your chosen root password was very simple.

  • source
  • hideshow 3 child comments
  • load more comments (3 replies)
    [–] 13 points 2 years ago

    I usually just follow this

  • source
  • load more comments
    view more: next β€Ί