Skip to content

Commit 5fd767d

Browse files
committed
Update
1 parent d7047b4 commit 5fd767d

File tree

2 files changed

+219
-91
lines changed

2 files changed

+219
-91
lines changed

technology/server/server-setup.md

Lines changed: 214 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Debian and Virtualmin Server Setup
22

33
> [!NOTE]
4-
> Last update: 2025-12-26
4+
> Last update: 2026-01-03
55
66
```.sh
77
# Settings
88
server_ip="100.00.000.01"
99
domain="website.com"
1010
domain_root_path="/home/$domain/public_html"
11+
admin_user="sysadmin"
1112
system_user="system_user"
1213
# system_user="www-data:www-data"
1314
database_name="database_name"
@@ -73,11 +74,177 @@ sudo apt install -y \
7374
# pyenv versions
7475
```
7576

77+
## User management
78+
79+
```.sh
80+
# Create the admin user
81+
sudo adduser $admin_user
82+
83+
# Add user to the sudo group
84+
sudo usermod -aG sudo $admin_user
85+
```
86+
87+
## SSH
88+
89+
(Local machine) Generate SSH key pair.
90+
91+
```.sh
92+
if [ -n "$admin_user" ] && [ -n "$domain" ] && [ -n "$server_ip" ]; then
93+
ssh-keygen -t ed25519 -C "$admin_user@$server_ip" -f ~/.ssh/id_ed25519_$domain
94+
else
95+
echo "Error: admin_user, domain, and/or server_ip is not defined"
96+
fi
97+
```
98+
99+
```.sh
100+
# (Optional) Backup SSH key to another folder
101+
cp ~/.ssh/id_ed25519_kaffeeart.eu /mnt/c/Users/$USER/Documents/
102+
cp ~/.ssh/id_ed25519_kaffeeart.eu.pub /mnt/c/Users/$USER/Documents/
103+
```
104+
105+
(Local machine) Get the SSH public key string.
106+
107+
```.sh
108+
cat ~/.ssh/id_ed25519_$domain.pub
109+
```
110+
111+
```.sh
112+
# echo sshpass -P \"passphrase\" -p \"PASSPHRASE\" -v ssh -i \"~/.ssh/id_ed25519_$domain\" -o ProxyCommand=\"cloudflared access ssh --hostname ssh.$domain\" \"$admin_user@$server_ip\"
113+
```
114+
115+
(Server) Add the ssh public key to the authorized keys.
116+
117+
```.sh
118+
# The public key string you copied from your local machine
119+
ssh_public_key="ssh-ed25519 AAAA... $admin_user@$server_ip"
120+
121+
# Create the directory for the admin user and set permissions
122+
sudo mkdir -p /home/$admin_user/.ssh
123+
chmod 700 /home/$admin_user/.ssh
124+
125+
# Append the key only if it doesn't already exist in the file
126+
if ! grep -qF "$ssh_public_key" /home/$admin_user/.ssh/authorized_keys 2>/dev/null; then
127+
echo "$ssh_public_key" >> /home/$admin_user/.ssh/authorized_keys
128+
fi
129+
130+
chmod 600 /home/$admin_user/.ssh/authorized_keys
131+
```
132+
133+
Configure SSH to use key-based authentication by adding "$admin_user" to the `AllowUsers` directive.
134+
135+
```.sh
136+
sudo nano /etc/ssh/sshd_config
137+
```
138+
139+
```.txt
140+
PubkeyAuthentication yes
141+
AllowUsers $admin_user
142+
```
143+
144+
```.sh
145+
sudo systemctl reload sshd
146+
```
147+
148+
(Local machine) Test the SSH connection.
149+
150+
```.sh
151+
ssh -i ~/.ssh/id_ed25519_$domain $admin_user@$server_ip
152+
```
153+
154+
Removing "root" from the `AllowUsers` directive. Completely disable "root" login.
155+
156+
```.sh
157+
sudo nano /etc/ssh/sshd_config
158+
```
159+
160+
Complete file:
161+
162+
```.txt
163+
# This is the sshd server system-wide configuration file. See
164+
# sshd_config(5) for more information.
165+
166+
Include /etc/ssh/sshd_config.d/*.conf
167+
168+
169+
# Connection settings
170+
171+
## Port
172+
Port 22
173+
174+
## Timeout and connection limits
175+
LoginGraceTime 60
176+
MaxAuthTries 3
177+
ClientAliveInterval 300
178+
ClientAliveCountMax 3
179+
MaxStartups 10:30:100
180+
AllowTcpForwarding no
181+
UseDNS no
182+
183+
184+
# Authentication settings
185+
186+
## Disable password authentication and enable key-based login
187+
PasswordAuthentication no
188+
PubkeyAuthentication yes
189+
KbdInteractiveAuthentication no
190+
191+
## Disable password-based root login
192+
PermitRootLogin no
193+
194+
## Allow a specific user to log in via SSH
195+
AllowUsers $admin_user
196+
197+
198+
# Other settings
199+
200+
## Enable Pluggable Authentication Modules (PAM) authentication
201+
UsePAM yes
202+
203+
## Disables printing the message of the day upon login
204+
PrintMotd no
205+
206+
## Override default of no subsystems
207+
Subsystem sftp /usr/lib/openssh/sftp-server
208+
```
209+
210+
Tests before restarting the ssh:
211+
212+
```.sh
213+
# Check SSH key existence
214+
sudo ls -la /home/$admin_user/.ssh/authorized_keys
215+
216+
# Check permissions
217+
sudo chown -R $admin_user:$admin_user /home/$admin_user/.ssh
218+
sudo chmod 700 /home/$admin_user/.ssh
219+
sudo chmod 600 /home/$admin_user/.ssh/authorized_keys
220+
221+
# Check for typos in the sshd config (if it returns nothing, config is valid)
222+
sudo sshd -t
223+
```
224+
225+
```.sh
226+
sudo systemctl reload sshd
227+
```
228+
229+
Keep current terminal window open and open a new terminal window trying to login as $admin_user.
230+
231+
(Server) Remove any server-generated SSH keys if needed. After confirming key-based login works, remove old server-generated keys if they exist.
232+
233+
```.sh
234+
ls -la /root/.ssh/
235+
ls -la /home/$admin_user/.ssh/
236+
# sudo rm -f /root/.ssh/id_rsa
237+
```
238+
239+
```.sh
240+
sudo systemctl reload sshd
241+
```
242+
76243
## Virtualmin
77244

78245
```.sh
79246
# Installation
80-
wget http://software.virtualmin.com/gpl/scripts/install.sh
247+
wget https://software.virtualmin.com/gpl/scripts/install.sh
81248
chmod a+x install.sh
82249
./install.sh
83250

@@ -114,6 +281,17 @@ After installation, login to Virtualmin and run the "Post-Installation Wizard".
114281
- Authentication provider: `Webmin``Webmin``Webmin Configuration``Two-Factor Authentication``Authentication provider`: `TOTOP Authenticator`.
115282
- Setup: `Webmin``Webmin``Webmin Users``Two-Factor Authentication``Enroll For Two-Factor Authentication`.
116283

284+
- Webmin Users:
285+
- Create a new privileged user: `Webmin``Webmin``Webmin Users``Create a new privileged user`:
286+
- `Webmin user access rights`:
287+
- `Username`: `$admin_user`.
288+
- `Password`: `Unix authentication`.
289+
- `Security and limits options`:
290+
- `Two-factor authentication type`: `Enable Two-Factor for User`.
291+
- `Available Webmin modules`: `Select all`.
292+
- Remove `root` Webmin user: Logout of the `root` Webmin user and login as the new `$admin_user` Webmin user. Then:
293+
- `Webmin``Webmin``Webmin Users``root``Delete`.
294+
117295
- Scheduled Upgrades:
118296
- Virtualmin → Dashboard → Package updates → Scheduled Upgrades:
119297
- `Check for updates on schedule`: `Yes, every week`.
@@ -178,83 +356,6 @@ sudo systemctl restart fail2ban
178356
# sudo systemctl enable saslauthd
179357
```
180358

181-
#### SSH
182-
183-
```.sh
184-
# Generate the SSH Key Pair
185-
ssh-keygen -t rsa -b 4096 -C "root@$server_ip"
186-
187-
# Add the Public Key to the Authorized Keys
188-
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
189-
chmod 700 /root/.ssh
190-
chmod 600 /root/.ssh/authorized_keys
191-
```
192-
193-
Save the RSA private key (`id_rsa`) on your local machine. Rename it as needed. PuTTYgen can convert the RSA private key to `.ppk`.
194-
195-
```.sh
196-
# Copy SSH key in Windows Subsystem for Linux (WSL)
197-
# mkdir -p ~/.ssh
198-
# chmod 700 ~/.ssh
199-
# cp "/mnt/c/Users/${USER}/Downloads/id_rsa" ~/.ssh/
200-
# chmod 600 ~/.ssh/id_rsa
201-
```
202-
203-
Configure SSH to Use Key-Based Authentication
204-
205-
```.sh
206-
nano /etc/ssh/sshd_config
207-
```
208-
209-
```.txt
210-
# This is the sshd server system-wide configuration file. See
211-
# sshd_config(5) for more information.
212-
213-
Include /etc/ssh/sshd_config.d/*.conf
214-
215-
216-
# Connection settings
217-
218-
## Port
219-
Port 22
220-
221-
## Timeout and connection limits
222-
LoginGraceTime 60
223-
MaxAuthTries 3
224-
ClientAliveInterval 300
225-
ClientAliveCountMax 3
226-
MaxStartups 10:30:100
227-
AllowTcpForwarding no
228-
UseDNS no
229-
230-
231-
# Authentication settings
232-
233-
## Disable password authentication and enable key-based login
234-
PasswordAuthentication no
235-
PubkeyAuthentication yes
236-
237-
## Disable password-based root login
238-
PermitRootLogin prohibit-password
239-
240-
## Allow a specific user to log in via SSH
241-
AllowUsers root
242-
243-
244-
# Other settings
245-
246-
## Enable Pluggable Authentication Modules (PAM) authentication
247-
UsePAM yes
248-
249-
## Disables printing the message of the day upon login
250-
PrintMotd no
251-
252-
## Override default of no subsystems
253-
Subsystem sftp /usr/lib/openssh/sftp-server
254-
```
255-
256-
Restart server.
257-
258359
#### Cloudflare Zero Trust
259360

260361
Cloudflare → `Zero Trust`.
@@ -329,7 +430,7 @@ sudo wtmpdb last | grep root
329430

330431
##### Grafana
331432

332-
Email alerts for any `root` login attempt (successful or failed) on the server via SSH, Virtualmin web panel, or server VNC console. Logs are stored externally in Grafana Cloud's free tier, ensuring they remain accessible even if the server is compromised and local logs are deleted.
433+
Email alerts for any `root` or `$admin_user` login attempt (successful or failed) on the server via SSH, Virtualmin web panel, or server VNC console. Logs are stored externally in Grafana Cloud's free tier, ensuring they remain accessible even if the server is compromised and local logs are deleted.
333434

334435
`Grafana``Alerts & IRM``Alerting``Manage contact points``Create contact point`:
335436

@@ -341,7 +442,7 @@ Email alerts for any `root` login attempt (successful or failed) on the server v
341442

342443
Enter alert rule name:
343444

344-
- `Name`: `Root Login`.
445+
- `Name`: `Server Login`.
345446

346447
Define query and alert condition:
347448

@@ -351,7 +452,7 @@ Define query and alert condition:
351452
sum by (instance, job, log_line) (
352453
count_over_time(
353454
{job="ssh_auth"}
354-
|~ "(?i)(sshd.*(accepted|failed).*for root|pam_unix\\((webmin|login):session\\).*session opened for user root|pam_unix\\(webmin:auth\\).*authentication failure.*user.*root)"
455+
|~ "(?i)(sshd.*(accepted|failed).*for (root|$admin_user)|pam_unix\\((webmin|login):session\\).*session opened for user (root|$admin_user)|pam_unix\\(webmin:auth\\).*authentication failure.*user.*(root|$admin_user))"
355456
!~ "(?i)(sudo:session|systemd-user:session)"
356457
| label_format log_line="{{ __line__ }}"
357458
[5m]
@@ -377,7 +478,7 @@ Set evaluation behavior:
377478

378479
Configure notification message:
379480

380-
- `Summary (optional)`: `Root Login on {{ $labels.instance }} ({{ $labels.job }})`.
481+
- `Summary (optional)`: `Login Event: {{ $labels.instance }} ({{ $labels.job }})`.
381482
- `Description (optional)`: `{{ $labels.log_line }}`.
382483

383484
#### FirewallD
@@ -465,13 +566,7 @@ Obtain core mail DNS records (`A` and `AAAA` records for the mail server; `MX` r
465566

466567
When adding the `A` and `AAAA` records for the mail server (e.g. `mail.website.com`) to Cloudflare, ensure its Proxy Status is set to `DNS only`. This is crucial for proper mail flow, as mail servers require direct IP connections.
467568

468-
Additionally, add the following record:
469-
470-
1. DMARC record
471-
472-
- Type: `TXT`
473-
- Name: `_dmarc`
474-
- Content: `v=DMARC1; p=none; fo=1; adkim=s; aspf=s`
569+
Additionally, enable `Email``DMARC Management`, which will add a DMARC record to the DNS.
475570

476571
### Sender Canonical Maps (Per-User Mapping)
477572

@@ -718,6 +813,35 @@ http {
718813
# Include Virtual Host Configurations
719814
include /etc/nginx/conf.d/*.conf;
720815
include /etc/nginx/sites-enabled/*;
816+
817+
# Cloudflare Real IP Restoration (updated from https://www.cloudflare.com/ips/)
818+
set_real_ip_from 173.245.48.0/20;
819+
set_real_ip_from 103.21.244.0/22;
820+
set_real_ip_from 103.22.200.0/22;
821+
set_real_ip_from 103.31.4.0/22;
822+
set_real_ip_from 141.101.64.0/18;
823+
set_real_ip_from 108.162.192.0/18;
824+
set_real_ip_from 190.93.240.0/20;
825+
set_real_ip_from 188.114.96.0/20;
826+
set_real_ip_from 197.234.240.0/22;
827+
set_real_ip_from 198.41.128.0/17;
828+
set_real_ip_from 162.158.0.0/15;
829+
set_real_ip_from 104.16.0.0/13;
830+
set_real_ip_from 104.24.0.0/14;
831+
set_real_ip_from 172.64.0.0/13;
832+
set_real_ip_from 131.0.72.0/22;
833+
834+
set_real_ip_from 2400:cb00::/32;
835+
set_real_ip_from 2606:4700::/32;
836+
set_real_ip_from 2803:f800::/32;
837+
set_real_ip_from 2405:b500::/32;
838+
set_real_ip_from 2405:8100::/32;
839+
set_real_ip_from 2a06:98c0::/29;
840+
set_real_ip_from 2c0f:f248::/32;
841+
842+
real_ip_header CF-Connecting-IP;
843+
real_ip_recursive off; # Not needed for CF-Connecting-IP (single IP)
844+
721845
}
722846
```
723847

technology/web-browser/readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
## General
44

5-
- [Disable Firefox Telemetry and Data Collection](https://github.com/K3V1991/Disable-Firefox-Telemetry-and-Data-Collection)
5+
### Betterfox Installation
6+
7+
Hardening Mozilla Firefox (Performance, Privacy, & AI Disable)
8+
9+
- In Mozilla Firefox: `about:support``Application Basics``Profile Folder``Open Folder` → Close Firefox → Paste Betterfox's [user.js](https://github.com/yokoffing/Betterfox/blob/main/user.js) (replace existing) → Restart Mozilla Firefox → Check if it worked (`about:support``Important Modified Preferences`).
610

711
## Extensions
812

0 commit comments

Comments
 (0)