12

Hey guys,

I finally come around and started the journey of self-hosting and decided to get a VPS. After securing it, by making login via public-key default, I installed CasaOS and instantly regretted it since it now can be reached freely from the internet. A while ago, I read that you can limit the incoming connection to only VPN and ssh. And configured a Wireguard-VPN on the server via pivpn. But the server can still be reached from the internet. So what do I have to do now? Is it even the right choice, or am I missing something? How do you guys secure your VPS?

all 21 comments
sorted by: hot top controversial new old
[-] brewery@feddit.uk 7 points 1 year ago

Before you go too far into it and spend lots of time, I think most VPS services let you installed a new OS on their admin site so you can start again from scratch. If you're not sure that is the right linux flavour, go for something else more mainstream so you can find lots of support online. Looking at the OS, I'm sure it might be good but I'm also sure you can install all the features very easily yourself, especially if it's just using docker mainly.

I second UFW. I found this guide useful: https://www.digitalocean.com/community/tutorials/ufw-essentials-common-firewall-rules-and-commands. You might want to try tailscale as others use it for easily setting up vpn access but not used it myself. Also go for fail2ban or, for more assurance but harder work, try crowdsec too.

You could also use cloudflare dns and add IP and/or country restrictions to block all traffic before it gets to your VPS. I have a country filter and it's crazy how many bots get blocked from all over!

[-] rmstyle@feddit.de 2 points 1 year ago

Thanks this is quite helpful!

[-] chiisana@lemmy.chiisana.net 1 points 1 year ago

Also before diving too deep into firewalls, which is a good idea none the less, just go to SSHd config and set ListenAddress to only listen on the VPN network address instead of public IP, and no one can connect via the public IP.

Keep it simple, and add complexity only as needed.

[-] Onion6068@feddit.de 2 points 1 year ago

I personally prefer using public key encryption over passwords for ssh authentication. There's no need to rely on third-party VPN providers (like ZeroTier or Tailscale) or hosting your own "vpn server" for that purpose as ssh trafic is already encrypted.

The drawback of following the route you suggested is that you have to operate yet another service that could be misconfigured, potentially causing you to lose access to your server. If you're keen on further restricting access, consider whitelisting your static(!) IP address, the IP address ranges associated with your provider or the ranges assigned to your country for an additional layer of security.

[-] chiisana@lemmy.chiisana.net 1 points 1 year ago

I agree. I have all my servers “in the open”, and only use VPN when I need to route my egress through a different geographical location. The reason I’m saying to use ListenAddress instead is because OP is already got the VPN setup, and seems like not going to change from it. No point introducing yet another piece of complexity such as firewall to the mix when their objective can be achieved with what they’re already using.

[-] Pulp@lemmy.dbzer0.com 3 points 1 year ago

Use ufw to only allow certain ports as needed

[-] ALERT@sh.itjust.works 3 points 1 year ago
[-] stown@lemmy.world 2 points 1 year ago* (last edited 1 year ago)

What's the point of renting a VPS if you only access it from your own network? I understand why a large company would do it (risk mitigation) but I don't understand why a self-hoster wouldn't just use an old computer at home. Your costs would be reduced and you could more easily control access.

Now that being said, most Cloud VPS providers have a firewall that you can configure from their web portal. If you whitelist your home network public IP then you can be sure that anyone connecting to your VPS will have to be doing so from your home network. You could do the same thing with UFW or Iptables on the VPS but I recommend using the external firewall because it won't take resources from your VPS while defending against a DDOS.

[-] rmstyle@feddit.de 1 points 1 year ago

The two main reasons I decided to opt for a VPS was, that I don't have a PC here that is efficient enough and the faster fresh installs and snapshots are a pro too.

[-] stown@lemmy.world 1 points 1 year ago

If you haven't already, check out Proxmox. It's an operating system that specializes in running Virtual Machines. If you run Proxmox at home you can have all the features that you just mentioned and more.

[-] Decronym@lemmy.decronym.xyz 2 points 1 year ago* (last edited 1 year ago)

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer Letters More Letters
IP Internet Protocol
SSH Secure Shell for remote terminal access
VPN Virtual Private Network
VPS Virtual Private Server (opposed to shared hosting)

3 acronyms in this thread; the most compressed thread commented on today has 12 acronyms.

[Thread #142 for this sub, first seen 17th Sep 2023, 13:05] [FAQ] [Full list] [Contact] [Source code]

[-] notepass@feddit.de 2 points 1 year ago

You can set up firewall rules that limit connections to certain ports. For example, you can disallow connections to everything but port 22 (which ssh runs on) to only allow access to the ssh server from outside. Same with VPN.

Read up on ufw (or iptables if you want to do it lower level and have a drink on hand).

[-] algenza@sos.nekoweb.my.id 0 points 1 year ago

@notepass@feddit.de @rmstyle@feddit.de Also, you can change the SSH port to something not 22. Some guide here. To connect to SSH, just use ssh -p PORT site.com

[-] notepass@feddit.de 2 points 1 year ago

You can, but you should configure your server in a way that this shouldn't be a security feature of your setup (e.g. key-auth as OP did). It does help to cut back on uninvited guests a lot tho.

[-] TexMexBazooka@lemm.ee 0 points 1 year ago
[-] notepass@feddit.de 1 points 1 year ago

ufw makes it way nicer to use tho. I only use iptables as I have a configuration script I wrote way back in the day.

[-] TexMexBazooka@lemm.ee 1 points 1 year ago

Yeah UFW is the way to go, but when you run into an embedded Linux device that only runs iptables and can only be accessed via ssh?

Well…. Keep that drink handy

[-] notepass@feddit.de 1 points 1 year ago

Yes, but how often does that happen to the average person?

[-] TexMexBazooka@lemm.ee 1 points 1 year ago

Deity of choice willing, never lol

[-] BlueBockser@programming.dev 1 points 1 year ago

My preferred option is to have the VPS inside a VPC that blocks all external traffic by default. Then I can open up specific ports for specific IP ranges.

The reason I prefer this over a firewall configuration on the VPS itself is that the latter seems far more error-prone to me. For example, I've had problems in the past with ufw and Docker where container ports were still reachable even though access was denied via ufw.

this post was submitted on 17 Sep 2023
12 points (80.0% liked)

Selfhosted

40247 readers
809 users here now

A place to share alternatives to popular online services that can be self-hosted without giving up privacy or locking you into a service you don't control.

Rules:

  1. Be civil: we're here to support and learn from one another. Insults won't be tolerated. Flame wars are frowned upon.

  2. No spam posting.

  3. Posts have to be centered around self-hosting. There are other communities for discussing hardware or home computing. If it's not obvious why your post topic revolves around selfhosting, please include details to make it clear.

  4. Don't duplicate the full text of your blog or github here. Just post the link for folks to click.

  5. Submission headline should match the article title (don’t cherry-pick information from the title to fit your agenda).

  6. No trolling.

Resources:

Any issues on the community? Report it using the report flag.

Questions? DM the mods!

founded 1 year ago
MODERATORS