this post was submitted on 02 Aug 2023
129 points (97.1% liked)

Selfhosted

39931 readers
463 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
 

Hey guys,

after reading up on selfhosting for weeks now I finally decided to take the plunge today and tried setting up my own nextcloud & jellyfin instances. For this purpose I am using a mini PC. (similiar to an Intel NUC)

Now I would like to make both services available to the internet so I could show images to friends while I'm at their place / watch movies with them.

The problem is I am currently not very educated on which security measures I would have to take to ensure that my server / mini PC doesn't immediately become an easy target for a hacker, especially considering that I would host private photos on the nextcloud.

After googling around I feel like I find a lot of conflicting information as well as write-ups that I don't fully grasp with my limited knowledge so if you guys have any general advice or even places to learn about all these concepts I would be absolutely delighted!

Thank you guys sooo much in advance for any and all help, the c/selfhosted community has been nothing but a great resource for me so far!!!

top 50 comments
sorted by: hot top controversial new old
[–] foonex@feddit.de 33 points 1 year ago (3 children)
  • Update frequently.
  • Use HTTPS. Redirect all HTTP traffic to HTTPS. If you use Caddy as a reverse proxy, this is pretty easy to set up. You‘ll want to get a domain name though.
  • If you use systemd, then systemd-analyze security (with man systemd.directives) is your friend. Be as restrictive as possible without breaking functionality.
  • Consider putting services like Jellyfin or Nextcloud in their own containers/VMs.

You don‘t need Cloudflare. I don‘t know why half the commenters in this thread recommend it. Cargo cult? You don‘t need DDOS protection. Nobody does DDOS attacks on random home servers. You don‘t need to hide your IP address either. Just make sure that you only expose port 80 and 443 to the internet and nothing else, and don‘t expose the admin interface of your router to the internet.

Alternatively as others have suggested, if you‘re not sure about your ability to secure everything, only expose your services over a Wireguard VPN. You don‘t really need Tailscale if you only want to manage a handful of devices, and you also don‘t need Tailscale‘s mesh networking for your use case.

[–] RxBrad@lemm.ee 4 points 1 year ago (2 children)

Cloudflare is nice if your ISP uses CGNAT or blocks incoming port traffic (e.g. Starlink or T-Mobile 5G Home Internet).

[–] foonex@feddit.de 7 points 1 year ago (1 children)

I see. That‘s a valid use case. Although, in the spirit of self-hosting, I personally would either get another ISP or run a reverse proxy on a cheap VPS and connect the homeserver to that via Wireguard.

[–] RxBrad@lemm.ee 1 points 1 year ago

Yep. I actually do both. Wireguard on Oracle Cloud for my Plex.

Cloudflare to serve up stuff like Overseerr & my WordPress blog.

[–] vividspecter@lemm.ee 3 points 1 year ago (1 children)

You can use tailscale for that too, but not raw wireguard.

[–] RxBrad@lemm.ee 1 points 1 year ago

I actually do use raw Wireguard on an Oracle VCN instance so I can share my Plex on T-Mobile Home Internet.

(Plex is against Cloudflare's ToS, which is why I don't use them for Plex)

Tailscale is good for people who are techy enough to use it. But it's not much help for my grandma if she wants to watch a Plex movie on her Roku.

[–] ttk@feddit.de 2 points 1 year ago* (last edited 1 year ago) (1 children)

Two remarks:

  • Containers are (and never were) no security instruments but only fancy ways of bundling things
  • You can open up other ports to the internet if you know what you're doing. My SSH is open to the internet, but only with key based auto, and in case i need pw auth as a backup, only with 2FA enabled
[–] foonex@feddit.de 1 points 1 year ago (1 children)

So, putting a process in its own network, file-system, user etc. namespace does not increase security in your opinion?

[–] ttk@feddit.de 1 points 1 year ago (2 children)

Indeed. Sure, they have these features, but only if used correctly while introducing vast more complexity (especially when being executed in a k8s environment,but also executed in plain docker). But, you know what also has security when used correctly? Plain linux.

What about 90% of all images on docker hub executing their main payload as root? What about many images bundling unnecessary software like an init system? What about the fact that even if you rm something in a dockerfile, it is still present, if you execute the rm in a different RUN command? What about every user in the docker group being implicit root on the host since they simply can mount the host's / inside their container? What about the reusing of layers between images like it is even intended?

Doesnt sound like a security tool, does it? Sure, it feels a bit like one, but it was never intended to be one, but a dependency and environment bundling tool which happens to use certain linux APIs which can be used for security. But it wraps lots of abstraction around it.

If you want to use these features for security, access them manually. But, OP said they are kind of a noob. Telling them to just use containers is dangerous and leads to false assumptions.

Source: i work as a cloud/container/devops/k8s expert for over 5 years.

load more comments (2 replies)
[–] goldgate@lemmy.world 31 points 1 year ago (2 children)
[–] ripe_banana@lemmy.world 22 points 1 year ago (1 children)

In the spirit of selfhosting, you can also host headscale. Its an open source implementation of the proprietary tailscale control plane.

It allows you to get over the 5 device limit, as well as keep your traffic on your devices. And, imo, it is pretty stable.

The only issue is that the control plane (by nature) has to be publically accessible. But imo it's way less of a security target than a massive app like nextcloud.

[–] vividspecter@lemm.ee 3 points 1 year ago (2 children)

It allows you to get over the 5 device limit, as well as keep your traffic on your devices. And, imo, it is pretty stable.

I believe tailscale raised the device limit relatively recently but I agree with you in that I prefer to self-host this type of thing.

[–] gornius@lemmy.world 4 points 1 year ago

AFAIK it's now 100, so basically unlimited for personal use.

load more comments (1 replies)
[–] Plod@programming.dev 17 points 1 year ago (1 children)

Another vote for Tailscale. Relatively easy to set up and can has some pretty cool features I’m still learning about. I also share my Jellyfin server with family and friends and it meets expectations.

[–] rambos@lemmy.world 24 points 1 year ago

I went for wireguard VPN instead of exposing services. Its much more safe afaik, but you have to configure each device you want to give access (aka scanning QR code). You also dont need to buy a domain for that. Exposed services would be easier to use, especially if you want to use it on many devices

[–] stown@sedd.it 19 points 1 year ago

If you are just exposing port 80 and 443 (standard web ports) cloudflare proxy is free and will work well to hide your IP.

Get yourself a domain name then use Cloudflare DNS to set an A record pointing to your home IP. If you have a dynamic IP (one that occasionally changes) you'll want to read this: https://developers.cloudflare.com/dns/manage-dns-records/how-to/managing-dynamic-ip-addresses/

[–] u_tamtam@programming.dev 17 points 1 year ago (1 children)

As soon as you put something up online, you will de facto become a target with nowhere to hide except offline. Your IP will be known and constantly hammered by more or less serious threats.

If you don't know the basics of Linux system administration and typical security measures, I would propose 2 approaches: you can go "the NAS way" and purchase something turnkey like a Synology (or anything on which you can easily spin up containers to host your services). You can expect a large part of the administration to be taken care of with sound default settings.

Another approach is to use a beginner friendly distro like https://yunohost.org/ , perhaps more involving, more risky, bit more rewarding.

Also, don't put anything up there like personal or valuable information (except if encrypted with local-only keys), expect to be hacked, expect to be wiped, and think early on about (off-site) backups.

[–] gornius@lemmy.world 1 points 1 year ago (1 children)

Yup, if you have SSH service open on port 22, you're automatically spammed by bots trying to brute force their way onto the system.

load more comments (1 replies)
[–] Smiling_Fanatic@lemmy.world 16 points 1 year ago* (last edited 1 year ago) (3 children)

Duckdns.org for dynamic dns. You can get a domain name like example.duckdns.org for free.

Caddyserver.com to reverse proxy to your running docker services. You’ll be able to set up jellyfin.example.duckdns.org

Crowdsec.net to secure the network

Tailscale for access to running docker services that you don’t need to share with friends.

[–] foonex@feddit.de 5 points 1 year ago (1 children)

Could you please be more specific what exactly Crowdsec brings to the table? In which way does it “secure the network”?

[–] das@lemellem.dasonic.xyz 4 points 1 year ago

Crowdsec will analyse the logs from your reverse proxy and identify malicious actors, bots and whatever else you configure it to. It then tells a "bouncer" (part of your reverse proxy) to reject the request, block the IP or redirect them to a captcha.

The downside is that it's kinda a pain to get set up, at least in my experience. It also stopped working without informing me and I've never been able to get it working again since. If you don't use docker the experience might be a bit easier.

[–] solberg@lemmy.blahaj.zone 2 points 1 year ago

DuckDNS is great, but you only need it if you have a dynamic IP. It’s worth checking if you have a static public IP before adding another layer of complexity.

[–] MaggiWuerze@feddit.de 2 points 1 year ago

There's even a Traefik Plugins for crowdsec. I guess it's time to play with my Traefik Config again

[–] Reborn2966@feddit.it 15 points 1 year ago* (last edited 1 year ago) (5 children)

i have a lot of stuff exposed to the web. i got a domain from godaddy, attached my public ip and created a subdomain for each service. than i have traefik that manage the tls and route each subdomain to each of the docker containers.

in total i have exposed 80, 443, and a random port i use for ssh. of course ssh is only by public key.

now i'm trying to set up fail2ban on the exposed services since someone could bruteforce them.

load more comments (5 replies)
[–] Kekin@lemy.lol 7 points 1 year ago (2 children)

The other day I learned about endlessh. I set that up, switched my actual sshd to listen on a different port, and the ssh login attempts from randoms essentially went down to 0. Pretty neat.

[–] prenatal_confusion@lemmy.one 5 points 1 year ago (2 children)

Sounds like security by obscurity to me. But still, nice result.

[–] confusedalex@feddit.de 2 points 1 year ago

It's more targeted to avoid automated attacks.

[–] winged_fluffy@kbin.social 1 points 1 year ago

Nah, as long as you keep following recommended security practices it can be useful to get rid of unneeded load being put on your server by malicious bots.
I had a lot of problems with botnets hammering my SSH service on my private VPS. Moving it to a different port would only work for a few days before they'd be back at it again.

I wasn't worried they'd get in. But logging in to my server would take ages because it was under so much load (VPS is pretty low-spec). Finally decided to shove my SSH service behind port knocking. Got rid of all the bots knocking at my door.

Obscurity has its uses, as long as you don't consider it a replacement for security. It's just an additional tool.

[–] mvirts@lemmy.world 2 points 1 year ago

Cool! I'm using fail2ban for cloud VMs, seems to keep the log chatter down

[–] nbailey@lemmy.ca 5 points 1 year ago (1 children)

Best advice I can give is to make sure the default virtualhost on nginx/apache just sends a 404 to all requests to your IP, and only serve the apps you want when they’re accessed by the correct hostname. The vast majority of spammy scanners are just hitting all public IPs, so as long as you don’t tell them what you’re hosting you’ll be alright.

Then, I’d advise having some sort of basic web application firewall (WAF). Modsecurity is a common one, NAXSI is another. These take some time to set up, but are quite good at absorbing attempted attacks.

[–] vegetaaaaaaa@lemmy.world 4 points 1 year ago (1 children)

I serve HTTP 403 for all requests to the default vhost and log them, harvest IPs through a log aggregator (or just fail2ban) and tag them as bad bots/scanners, and eternal-ban them on all my hosts. Currently have 98451 addresses or networks in my ipset for these.

For requests to actual domains, I ban after a few unsuccessful authentication attempts. A WAF is nice to have (tedious but fun to set up) - currently working on improving my Modsecurity setup.

Other than that there is already good advice here:

  • keep OS/packages/installed services up-to-date
  • only run software from trusted (ideally signed) sources
  • use host and network-based firewalls
  • use strong encryption and authentication everywhere
  • only expose what is absolutely required
  • implement good privilege separation (even dedicated users for each app/service, proper file ownership/permissions goes a long way)
  • run scanners to detect possible misconfigurations/hardening measures (systemd-analyze security was mentioned, I also like lynis and debsecan)
  • set up proper logging/monitoring alerting
[–] nbailey@lemmy.ca 2 points 1 year ago

Yep, banning scanners with ipset lists is a great solution. I use a slightly convoluted method to perma-ban abusers, but fail2ban also works great.

https://nbailey.ca/post/block-scanners/

[–] bravesilvernest@lemmy.ml 5 points 1 year ago

My approach was to set it all up internally, create a wireguard VPN accesspoint and only open that up. That way I don't have as much to worry as much within the network (still use generated passwords for things) and able to access it anywhere.

Granted, you asked about opening up to the www. I'd suggest buying a domain through cloudfront, setting up an nginx instance that proxies traffic (think nextcloud.mydomain.com), and have it only accept connections from cloudfront servers.

That allows you SSL termination, pretty good bot coverage, and a nice domain name to share as needed.

[–] wedge_film@lemmy.dbzer0.com 3 points 1 year ago (1 children)

General advice would be to look boring and hide your IP as much as you are able (get a domain). As long as you're not looking juicy you won't attract skilled attention. It's like locking a bike, most bad actors will just pass by looking around for one without a lock or a real fancy one worth their resources.

You can utilize Cloudflare's free offerings, starting with simple stuff. Their DNS Proxy is essentialy a single-click but will help substantially. You can build on top of that with simple WAF rules, such as droping connection attempts from IPs originating from countries notorious for "poking around". You can also reverse that rule and whitlelist only your country.

Keep your firewall tight, don't expose other ports, put your services behind a reverse proxy and redirect everything to HTTPS. Start simple, constantly improve, learn more advanced methods/concepts.

[–] Poutinetown@lemmy.ca 10 points 1 year ago (1 children)

How is getting a domain protecting you IP? Wouldn't your IP still be accessible even after you link it to a domain?

[–] khornechips@yiffit.net 7 points 1 year ago (2 children)

Yes, but by proxying your traffic via cloudflare your domain will point to their IP instead of yours directly.

[–] Poutinetown@lemmy.ca 2 points 1 year ago (2 children)

So it makes you IP less discoverable. However, if someone finds your IP randomly (through brute force), would you still be vulnerable? Or is it possible to only port forward to a static CF address so only CF can connect to you outside of your home network?

[–] khornechips@yiffit.net 5 points 1 year ago

You would, but that’s where your firewall and SSL certificates come into play. I use a reverse proxy and forward port 80/443 directly to it. Everything I host resolves to a CNAME in Cloudflare and my proxy responds with a 404 to any unknown requests.

load more comments (1 replies)
[–] wedge_film@lemmy.dbzer0.com 2 points 1 year ago

My bad, I should have worded that better, thank you for making it clear, that's exactly what I had in mind.

[–] xtremeownage@lemmyonline.com 3 points 1 year ago

Just make sure you know how to properly secure your network, check logs, ensure you have logs. ensure you have backups in a secure location.....

And, be prepared for the constant barrage of vulnerability scans, and login attempts.

[–] datallboy@lemmy.techhaven.io 2 points 1 year ago (3 children)

It comes down to using secure passwords, 2 factor authentication, and updating software as soon as you can.

Check out Cloudflare's zero tier tunnel to only expose the services you need without port forwarding. Added benefit of masking your home's IP behind Cloudflare to prevent DDOS. Only downside is you need your own domain.

[–] foonex@feddit.de 3 points 1 year ago

Why would anyone DDOS a random home server? I don‘t think OP has to worry about that.

[–] FairlyConstantFox@lemmy.world 2 points 1 year ago

This is what I've ended up doing. I originally wanted to use the DNS proxy option, but I was getting people randomly scanning my home IP anyway.

[–] emuspawn@orbiting.observer 1 points 1 year ago

The multifactor can't be understated as part of your security stance! I turn it on and enforce it on my home network for any service I host that supports it. And like mentioned elsewhere, only 80 and 443 are opened and they go straight through a proxy.

load more comments
view more: next ›