TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Server Setup Basics for Self Hosting

169 pointsby joelp9 months ago

19 comments

solatic9 months ago
Especially when writing a tutorial for beginners - please use the long-form flags (e.g. sudo usermod --append --groups sudo newuser) instead of short-form flags (e.g. sudo usermod -aG sudo newuser). Short-form flags make commands look like arcane voodoo magic. They make sense only to help you save time entering commands if you know them by heart already. Tutorials are read by beginners who are not necessarily familiar with the commands in the first place - long-form flags help communicate what these commands are actually doing and thus make for a more effective tutorial.
评论 #41356459 未加载
评论 #41358497 未加载
评论 #41354887 未加载
jks9 months ago
I recommend checking out Caddy &lt;<a href="https:&#x2F;&#x2F;caddyserver.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;caddyserver.com&#x2F;</a>&gt;, which replaces both Nginx and Certbot in this setup.<p>Tailscale &lt;<a href="https:&#x2F;&#x2F;tailscale.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tailscale.com&#x2F;</a>&gt; can remove the need to open port 22 to the world, but I wouldn&#x27;t rely on it unless your VPS provider has a way to access the server console in case of configuration mistakes.
评论 #41354068 未加载
评论 #41354632 未加载
评论 #41355449 未加载
评论 #41354835 未加载
hobobaggins9 months ago
I&#x27;d switch to Userify if you have a team to distribute keys for, because it&#x27;s ultra-lightweight and also keeps you from messing up permissions on the ssh key&#x2F;directory, which I&#x27;ve done too many times! (also it does sudo which is quite nice)<p>Also, restarting ssh will not boot you out of the session (your session has already been forked as a different process), so leave your terminal window open (to fix any screwups) and then log in on a separate window on the new port and just make sure you can get in.<p>For backups, don&#x27;t set up logins from your main server(s) to your backup server; log in from your backup server to your main server. That way, if someone breaks into your main server, they can&#x27;t get into your backup server.
erros9 months ago
You may want to update this post to disable password authentication, and thus you&#x27;ll no longer need to install fail2ban. An important goal is to tighten your attack surface, not expand it. At this point you will still have an exposed SSHd server, so I&#x27;d recommend throwing the server under tailscale. You can setup the SSHd listener to use your tailscale IP or setup tailscale for SSH via ACLs (<a href="https:&#x2F;&#x2F;tailscale.com&#x2F;tailscale-ssh" rel="nofollow">https:&#x2F;&#x2F;tailscale.com&#x2F;tailscale-ssh</a>).<p>Additionally you can further tighten controls of incoming logins with the use of AllowGroups to tighten your controls on which groups can log into the system. This would mitigate a scenario where an adversary is able to escalate enough privileges to write an .authorized_keys file to a non-privileged user which may have a shell still configured.<p>Finally, unless you&#x27;re treating this server as a bastion host of sorts, you probably should disable forwarding for agents or X11 etc. We&#x27;ve seen a lot of adversaries move laterally due to this agent forwarding.
评论 #41354057 未加载
jw_cook9 months ago
At the end of the article, there&#x27;s a link to a script[1] that does the steps covered in the article.<p>That got me thinking: how do other self-hosters&#x2F;homelabbers here go about automating their server setups? None&#x2F;purely manual? One big shell script? Multiple scripts wrapped in a Makefile (or justfile, or other command runner)? More enterprisey provisioning&#x2F;automation tools like Ansible, Puppet, etc.?<p>[1] <a href="https:&#x2F;&#x2F;git.sovbit.dev&#x2F;Enki&#x2F;sovran-scripts" rel="nofollow">https:&#x2F;&#x2F;git.sovbit.dev&#x2F;Enki&#x2F;sovran-scripts</a>
评论 #41354392 未加载
评论 #41354614 未加载
评论 #41354369 未加载
评论 #41354366 未加载
评论 #41357812 未加载
评论 #41354623 未加载
评论 #41354990 未加载
评论 #41354418 未加载
tiffanyh9 months ago
Love seeing devops post on HN.<p>Wish it included server monitoring as a section.
评论 #41357942 未加载
评论 #41363376 未加载
remram9 months ago
&gt; Differential backups back up all the changes since the last full backup (...) An incremental backup backs up data that was changed since the last backup<p>I&#x27;m not sure I understand the distinction?
评论 #41353738 未加载
评论 #41353704 未加载
评论 #41353723 未加载
评论 #41353719 未加载
AtlasBarfed9 months ago
So... about docker, did they backtrack on their licensing landgrab?<p>About a year ago I swear everyone was going to podman, but in the last few months I see nothing but docker references.<p>Podman is supposed to be drop-in. Well, it was advertised. I haven&#x27;t touched anything in six months.
评论 #41354032 未加载
评论 #41354013 未加载
评论 #41354664 未加载
abhinavk9 months ago
&gt; You want to use SSH (Secure Shell) and make sure that SSH is the only way to log in.<p>Some distributions (like openSuSE) also enable KbdInteractiveAuthentication by default so just disabling PasswordAuthentication won&#x27;t work.
评论 #41353793 未加载
评论 #41353675 未加载
enkimin9 months ago
Article author here. Glad some people found this useful and to those with suggestions, ill keep those in mind when updating the post.<p>Cheers.
chadsix9 months ago
And for those of you that don&#x27;t have an external IP, you can use services that provide egress for you like IPv6.rs. [1]<p>[1] I&#x27;m DevOps there! ;)
评论 #41354507 未加载
Cyph0n9 months ago
Great post! I (relatively) recently switched my primary home server over to NixOS and am now a huge fan of it as a distribution for self-hosting.<p>Here is how setting this all up would like in NixOS (modulo some details &amp; machine-specific configuration). It&#x27;s &lt;100 lines, can be executed&#x2F;configured with a single CLI command (even from a different machine!), rolled back easily if things go wrong, and can be re-used on any NixOS machine :)<p><pre><code> { networking = { # Server hostname hostName = &quot;myserver&quot;; # Firewall firewall = { enable = true; allowedTCPPorts = [ 80 443 2222 ]; }; }; # Users users.users = { newuser = { isNormalUser = true; home = &quot;&#x2F;home&#x2F;newuser&quot;; hashedPassword = &quot;my-hashed-pwd&quot;; openssh.authorizedKeys.keys = [ &quot;my-pub-key&quot; ]; }; }; # SSH services.openssh = { enable = true; ports = [ 2222 ]; settings = { PermitRootLogin = &quot;no&quot;; PasswordAuthentication = false; AllowUsers = [ &quot;newuser&quot; ]; }; extraConfig = &#x27;&#x27; Protocol 2 # Use only SSH protocol version 2 MaxAuthTries 3 # Limit authentication attempts ClientAliveInterval 300 # Client alive interval in seconds ClientAliveCountMax 2 # Maximum client alive count &#x27;&#x27;; }; services.fail2ban.enable = true; # Nginx + SSL via LetsEncrypt services.nginx = { enable = true; recommendedOptimisation = true; recommendedProxySettings = true; recommendedTlsSettings = true; virtualHosts = { &quot;example.com&quot; = { locations.&quot;&#x2F;&quot; = { proxyPass = &quot;http:&#x2F;&#x2F;localhost:8080&quot;; proxyWebsockets = true; }; forceSSL = true; enableACME = true; }; }; }; security.acme = { acceptTerms = true; defaults.email = &quot;myemail@gmail.com&quot;; certs.&quot;example.com&quot; = { dnsProvider = &quot;cloudflare&quot;; environmentFile = .&#x2F;my-env-file; }; }; # Logrotate services.logrotate = { enable = true; configFile = pkgs.writeText &quot;logrotate.conf&quot; &#x27;&#x27; &#x2F;var&#x2F;log&#x2F;nginx&#x2F;*.log { weekly missingok rotate 52 compress delaycompress notifempty create 0640 www-data adm sharedscripts postrotate [ -f &#x2F;var&#x2F;run&#x2F;nginx.pid ] &amp;&amp; kill -USR1 `cat &#x2F;var&#x2F;run&#x2F;nginx.pid` endscript } &#x27;&#x27;; }; # Bonus: auto-upgrade from GH repo system.autoUpgrade = { enable = true; flake = &quot;github:myuser&#x2F;nixos-config&quot;; flags = [ &quot;-L&quot; # print build logs &quot;--refresh&quot; # do not use cached Flake ]; dates = &quot;00:00&quot;; allowReboot = true; randomizedDelaySec = &quot;45min&quot;; }; }</code></pre>
评论 #41353952 未加载
评论 #41355046 未加载
nihilius9 months ago
Here are some &quot;First Things on a Server&quot; Notes. <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;klaushardt&#x2F;07f5e3068355aafc2dce660a54be1ea7" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;klaushardt&#x2F;07f5e3068355aafc2dce660a5...</a><p>Ansible&#x2F;Puppet or NixOS would be better, but this is what works in Self Hosting.
Sandbag58029 months ago
Hey I just want to say thank you for the write up. I just got into the hobby of self hosting my own applications and it&#x27;s quite a bit. I appreciated your sections about logging and user management.
davidmitchell29 months ago
While these seems to be secure... tampering with default settings always cause PITA; especially during automated upgrades. In addition, ssh port changes are all security thru obscurity.
评论 #41355344 未加载
thijsb9 months ago
Why the `sudo ufw allow outgoing`? Wouldn&#x27;t it be worth to deny all to prevent extrusion and only open ports for services that need to communicate externally?
ValtteriL9 months ago
A monitoring setup with for instance Prometheus+Grafana would be a great addition to this.<p>And then maybe automating all of it with something like Ansible.
voidUpdate9 months ago
With SSH Keys, do you have to just carry around your private key everywhere on a usb or something if you want to connect from multiple locations? Sometimes I find myself somewhere I&#x27;ve never been and I want to connect to my server. With a password that&#x27;s easy, I just type it in, but I can&#x27;t exactly create a new private key to access the server when I don&#x27;t have access to the server in the first place
评论 #41355271 未加载
评论 #41355269 未加载
crdrost9 months ago
Qq, do people doing their own server setup like this use containerization at all?<p>When I looked at it, it was like “yeah you can run Docker or k3s,” and I think Hashicorp had their own version, but it seemed like folks didn&#x27;t really bother? Also like setting up virtual networks among VPSes seemed like it required advanced wizardry.
评论 #41353917 未加载
评论 #41353941 未加载
评论 #41354784 未加载
评论 #41354042 未加载