Compare commits

..

No commits in common. "70a815b135f366c9c097fcfe2af52c45d61060c6" and "de8c29591b1288fb1931e4f756f1de63009d6295" have entirely different histories.

10 changed files with 45 additions and 117 deletions

View File

@ -1,43 +1,41 @@
# Guide for systems / infra maintanance and creation # Guide for systems / infra maintanance and creation
This guide provides good defaults and recipes on how to set up infra in a reliable, stable, effecient and secure way. This guide is assuming you are setting up or maintaining an AlmaLinux (9, 10) server.
It guides you from setting up a fresh machine, to installing build dependencies, configuring the firewall, serving and monitoring your apps and lastly protecting them from DDOS.
It guides you from setting up a fresh machine, to installing build dependencies, configuring the firewall, serving and monitoring your apps, protecting them from DDOS and more. ## [Setting up a new machine](setup.md)
It assumes you are setting up or maintaining an AlmaLinux (9, 10) or a similar RHEL-based server. Prepare a new machine for use with an `admin` user. Lock out everything but to it.
## [Setting up a new machine](00_setup.md) ## [Installing aplications and build tools](applications.md)
Prepare a new machine for use with an `admin` user. Lock out everything but SSH to it.
## [Installing aplications and build tools](01_applications.md)
Download packages to build future applications such as NodeJS / Rust. Download packages to build future applications such as NodeJS / Rust.
Set up your apps on `/usr/local/bin/` path. Set up your apps in `/srv/` partition.
## [Firewall (opening/checking ports)](02_firewall.md) ## [Firewall (opening/checking ports)](firewall.md)
How to open firewall to let outside traffic to your apps. How to check and set firewall zones. How to open firewall to let outside traffic to your apps.
If your service is timing out (nothing gets thru) this is probably the answer.
## [Running services and logging with systemd](03_systemd.md) ## [Running services and logging with systemd](systemd.md)
How to set up a new systemd service and read its logs. How to set up a new systemd service and read its logs.
## [Nginx & Certbot](04_nginx-certbot.md) ## [Nginx & Certbot](nginx-certbot.md)
How to set up Nginx and Certbot to serve your apps with an SSL cert for your desired domain. How to set up Nginx and Certbot to serve your apps with an SSL cert for your desired domain.
## [Monitoring servers (Beszel)](05_beszel.md) ## [Monitoring servers (Beszel)](beszel.md)
How to monitor servers with Beszel tool which gives you system load stats and systemd service stats. How to monitor servers with Beszel tool which gives you system load stats and systemd service stats.
## [Monitoring websites and apis and serving a Status Page (Uptime Kuma)](06_uptime-kuma.md) ## [Monitoring websites and apis and serving a Status Page (Uptime Kuma)](uptime-kuma.md)
How to monitor your services and websites with Open Kuma. How to monitor your services and websites with Open Kuma.
## [Protecting your services and websites with BunnyCDN](07_bunny-cdn.md) ## [Protecting your services and websites with BunnyCDN](bunny-cdn.md)
How to protect and hide your services and websites from DDOS attacks. How to protect and hide your services and websites from DDOS attacks.
## [AlmaLinux / RHEL linux](08_alma-linux.md) ## [WTF is AlmaLinux](alma-linux.md)
Could be the first link, but really its not that important.

View File

@ -1,29 +1,9 @@
# Why .. Alma Linux? # Why and why .. Alma Linux?
AlmaLinux is a continuation of open source work for enterprise grade Red Hat Enterprise Linux (RHEL). AlmaLinux is a continuation of open source work for enterprise grade Red Hat Enterprise Linux (RHEL).
Its a spiritual successor to CentOS and bug-for-bug compatible with RHEL same as Rocky Linux but without the toxic community. Its a spiritual successor to CentOS and bug-for-bug compatible with RHEL same as Rocky Linux but without the toxic community.
## Enabling SELinux ### What about Debian / Ubuntu ???
If its disabled on boot, enable it back with
1. Change the value of `SELINUX` to `SELINUX=enforcing` in `/etc/selinux/config`
2. Enable it on boot (if it was disabled before)
```sh
sudo grubby --update-kernel ALL --remove-args selinux
```
3. Reboot
4. You might need to update the folders where permissions are wrong. Use the command:
```sh
restorecon -Rv /usr/local/bin/your_repo
```
### What about Debian / Ubuntu ?
Tbh, at the time of setting up new servers the `Debian` install was not working on my host, thats why i picked `AlmaLinux` for all installations to keep them uniform. Tbh, at the time of setting up new servers the `Debian` install was not working on my host, thats why i picked `AlmaLinux` for all installations to keep them uniform.
Even though its a move from our usual package manager (`apt`) its the same shit. It uses `dnf` and `yum` and everything works the same. Even though its a move from our usual package manager (`apt`) its the same shit. It uses `dnf` and `yum` and everything works the same.

View File

@ -1,30 +1,15 @@
# Installing applications and their dependencies # Installing applications and their dependencies
## Create your SSH keys for Github ## Put your apps in `/srv/`
Generate ssh-key for private Git porjects
then copy it to Github project under Settings -> Deploy keys
```sh
ssh-keygen -t ed25519
cat /home/admin/.ssh/id_ed25519.pub # (or whatever u named it, if u only need it for 1 project, keep it default)
```
## Put your apps in `/usr/local/bin/`
Do not just install stuff in `/home/` dirs. Do not just install stuff in `/home/` dirs.
Rather `git clone` the repos to your home and then move it to `/usr/local/bin/` partition. Rather `git clone` the repos to your home and then move it to `/srv/` partition.
If SELinux is turned on you might also wanna do `restorecon` to let `systemctl` service be able to use it.
```sh ```sh
sudo mv your_repo /usr/local/bin/your_repo sudo mv your_repo /srv/your_repo
restorecon -Rv /usr/local/bin/your_repo
``` ```
This will reset
This way other users of the system can also access and use your app without letting them into your $HOME. This way other users of the system can also access and use your app without letting them into your $HOME.
## Installing NodeJS ## Installing NodeJS

View File

@ -21,7 +21,7 @@ This will install the beszel binary. The beszel itself will update itself if you
Even though beszel operates on Websockets primarily it will SSH into the machine in case Websocket connection is lost. Even though beszel operates on Websockets primarily it will SSH into the machine in case Websocket connection is lost.
Make sure port `45876` on target machine to SSH into is open. Make sure port `45876` on target machine to SSH into is open.
If you havent done so before, check [Firewall](02_firewall.md) section for extra tips, but here is a quick oneliner: If you havent done so before, check [Firewall](firewall.md) section for extra tips, but here is a quick oneliner:
```sh ```sh
sudo firewall-cmd --permanent --zone=public --add-port=45876/tcp && sudo firewall-cmd --permanent --zone=public --add-port=45876/tcp &&

View File

@ -8,6 +8,16 @@ BunnyCDN is your friend in 3 ways at least:
It operates with "zones". Think 1 zone = 1 service / website / url you run. It operates with "zones". Think 1 zone = 1 service / website / url you run.
## No caching please
By default if server doesnt include a `Cache-control` header, bunny will cache it.
To make it never cache, include header `Cache-control` with value `no-cache` in your responses.
## Purging cache
To purge the cache on BunnyCDN, there is a button on the top right of the UI.
## How to add a service / website to BunnyCDN ## How to add a service / website to BunnyCDN
Consult the screenshots below on how to set BunnyCDN in your browser. Consult the screenshots below on how to set BunnyCDN in your browser.
@ -32,14 +42,4 @@ Enter it into your DNS and Verify SSL back on BunnyCDN.
![New zone 4](public/bunny4.png "Step 4") ![New zone 4](public/bunny4.png "Step 4")
Voila, this is it. Voila, this is it
## How to disable caching
By default if server doesnt include a `Cache-control` header, bunny will cache it.
To make it never cache, include header `Cache-control` with value `no-cache` in your responses.
## Purging cache
To purge the cache on BunnyCDN, there is a button on the top right of the UI.

View File

@ -2,7 +2,7 @@
We use `firewalld` to configure firewalls. It uses so called "zones" to define the rules. We use `firewalld` to configure firewalls. It uses so called "zones" to define the rules.
In the [Setup](00_setup.md) guide we have installed and set up `firewalld`, left `ssh` open and closing all other traffic by setting the default zone to "drop". In the [Setup](setup.md) guide we have installed and set up `firewalld`, left `ssh` open and closing all other traffic by setting the default zone to "drop".
Check [Offish guide](https://www.redhat.com/en/blog/firewalld-rules-and-scenarios) for more details. Check [Offish guide](https://www.redhat.com/en/blog/firewalld-rules-and-scenarios) for more details.
@ -42,15 +42,14 @@ sudo firewall-cmd --zone=public --list-ports
Change the default zone to `public` with Change the default zone to `public` with
```sh ```sh
sudo firewall-cmd --set-default-zone=public sudo firewall-cmd --permanent --zone=public
``` ```
Then open the relevant ports and reload the firewall Then open the relevant ports and reload the firewall
```sh ```sh
sudo firewall-cmd --permanent --zone=public --add-port=22/tcp # SSH sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --permanent --zone=public --add-port=80/tcp # HTTP sudo firewall-cmd --permanent --zone=public --add-port=443/tcp
sudo firewall-cmd --permanent --zone=public --add-port=443/tcp # HTTPS
sudo firewall-cmd --reload sudo firewall-cmd --reload
``` ```
@ -59,7 +58,6 @@ OR
You can also open "services", these are just aliases for port/protocol pairing (aka service=http is equal to port 80/tcp) You can also open "services", these are just aliases for port/protocol pairing (aka service=http is equal to port 80/tcp)
```sh ```sh
sudo firewall-cmd --permanent --zone=public --add-service=ssh
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload sudo firewall-cmd --reload

View File

@ -85,22 +85,3 @@ server {
} }
``` ```
Test and reload nginx by:
```sh
# Test configuration
sudo nginx -t
# Reload nginx
sudo systemctl reload nginx
```
## Deleting Certbot certificates
```sh
# List your certificates
sudo certbot certificates
# Delete by name
sudo certbot delete --cert-name sub.domain.com
```

View File

@ -13,8 +13,7 @@ dnf update -y && dnf upgrade -y
Then install the neccessary packages Then install the neccessary packages
```sh ```sh
dnf install -y epel-release firewalld bind-utils git dnf install -y epel-release firewalld bind-utils git fail2ban neovim
dnf install -y fail2ban neovim
``` ```
`epel-release` is neccessary to get fail2ban and some later dependencies `epel-release` is neccessary to get fail2ban and some later dependencies
@ -35,7 +34,7 @@ firewall-cmd --add-service=ssh --permanent &&
firewall-cmd --reload firewall-cmd --reload
``` ```
⚠️ *`drop` zone will just drop all traffic if you dont configure it to use `public` zone like we show in [Firewall](02_firewall.md) section. If connections time out this is likely the reason.* ⚠️⚠️⚠️ `drop` zone will just drop all traffic if you dont configure it to use `public` zone like we show in [Firewall](firewall.md) section. If connections time out this is likely the reason. ⚠️⚠️⚠️
## Unattended upgrades ## Unattended upgrades
@ -79,7 +78,7 @@ usermod -aG wheel admin # Give elevated (sudo) privileges to the user
Switch to `admin` account Switch to `admin` account
```sh ```sh
su - admin su -i admin
``` ```
Create files and paste your public key Create files and paste your public key
@ -92,29 +91,16 @@ nvim .ssh/authorized_keys # paste relevant SSH public keys in here
Try opening a new terminal and ssh-ing into `admin` user on the server, it should work. Try opening a new terminal and ssh-ing into `admin` user on the server, it should work.
### Locking the `admin` account password login
⚠️ *Be sure you can SSH with another sudo enabled account like `root` otherwise you WILL LOCK YOURSELF out of the machine.*
Run the following one-liner:
```sh
echo -e '\nMatch User admin\n PasswordAuthentication no' | sudo tee -a /etc/ssh/sshd_config > /dev/null && \
sudo sshd -t && sudo systemctl restart sshd
```
It will add an entry to the end of the file for user `admin` that prohibits logging in with user/pass.
### Locking the `root` account ### Locking the `root` account
⚠️ *Be sure you can SSH with another sudo enabled account like `admin` otherwise you WILL LOCK YOURSELF out of the machine.* ⚠️⚠️⚠️ Be sure you can SSH with another sudo enabled account like `admin` otherwise you WILL LOCK YOURSELF out of the machine. ⚠️⚠️⚠️
Go back to `root` account now, otherwise you will need to `sudo` the commands below. Go back to `root` account now, otherwise you will need to `sudo` the commands below.
The following commands will lock out the root by configuring `/etc/ssh/sshd_config` file. The following commands will lock out the root by configuring `/etc/ssh/sshd_config` file.
```sh ```sh
sed -i '/^PermitRootLogin/c\PermitRootLogin no' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sed -i '/^PasswordAuthentication/c\PasswordAuthentication no' /etc/ssh/sshd_config sed -i 's/#PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
systemctl restart sshd systemctl restart sshd
```` ````

View File

@ -26,9 +26,9 @@ Wants=network.target
[Service] [Service]
# Set the working directory where your binary resides # Set the working directory where your binary resides
WorkingDirectory=/usr/local/bin/YOUR_PATH WorkingDirectory=/srv/YOUR_PATH
# Absolute path to your binary # Absolute path to your binary
ExecStart=/usr/local/bin/YOUR_PATH/target/release/BINARY_NAME ExecStart=/srv/YOUR_PATH/target/release/BINARY_NAME
# Ensure the service restarts on failure # Ensure the service restarts on failure
Restart=always Restart=always