@@ -14,6 +14,197 @@ The following is tested and used on Ubuntu 22.04.
1414| 14.04 LTS | Trusty Tahr | Debian 7 | Wheezy |
1515| 12.04 LTS | Precise Pangolin | Debian 6 | Squeeze |
1616
17+ ## New VPS
18+
19+ Some basics config for any new machine for a new virtual private server (e.g. from Azure, AWS, GCP, Hetzner, ...)
20+
21+ ### Tools
22+
23+ This is an overview of all tools used:
24+
25+ | Category | Tool | Type | License / Source |
26+ | --------------- | ----------------------- | ----------- | ---------------- |
27+ | OS & Packages | apt, systemctl | Built-in | Debian/Ubuntu |
28+ | Firewall | UFW | Open-source | Canonical |
29+ | SSH | OpenSSH | Open-source | BSD-style |
30+ | Web Server | Nginx | Open-source | 2-clause BSD |
31+ | SSL | Certbot / Let’s Encrypt | Open-source | EFF / ISRG |
32+ | Runtime | Node.js / npm | Open-source | MIT |
33+ | Process Manager | PM2 | Open-source | AGPL |
34+ | Monitoring | htop / iotop | Open-source | GPL |
35+ | Backups | tar / cron | Built-in | GNU |
36+ | Updates | unattended-upgrades | Open-source | Debian |
37+ | Auditing | Lynis | Open-source | GPLv3 |
38+
39+ ### Steps
40+
41+ Read this as a basic setup and security checklist (there is always more that can be done : D ):
42+
43+ Connect to your new server and apply updates:
44+
45+ ``` sh
46+ ssh root@vps-ip
47+ apt update && apt upgrade -y
48+ uname -a
49+ cat /etc/os-release
50+ ```
51+
52+ Change the root password
53+
54+ ``` sh
55+ passwd
56+ ```
57+
58+ Create a secondary (unprivileged) user, give it sudo access:
59+
60+ ``` sh
61+ adduser myusername
62+ usermod -aG sudo myusername
63+ groups myusername # myusername : myusername sudo
64+ su - myusername
65+ sudo whoami # root
66+ ```
67+
68+ #### SSH
69+
70+ On your local machine generate SSH keys:
71+
72+ ``` sh
73+ ssh-keygen -t ed25519 -C " email@ddress.com"
74+ cat ~ /.ssh/id_ed25519.pub
75+ ```
76+
77+ On the server (as your new user, not root):
78+
79+ ``` sh
80+ mkdir -p ~ /.ssh
81+ chmod 700 ~ /.ssh
82+ nano ~ /.ssh/authorized_keys # paste your public key here
83+ chmod 600 ~ /.ssh/authorized_keys
84+ ```
85+
86+ Test login:
87+
88+ ``` sh
89+ ssh myusername@vps-ip
90+ ```
91+
92+ Edit SSH configuration: ` sudo nano /etc/ssh/sshd_config ` and add/edit these lines:
93+
94+ ``` txt
95+ PasswordAuthentication no
96+ PubkeyAuthentication yes
97+ ```
98+
99+ Check if ` /etc/ssh/sshd_config.d/50-cloud-init.conf ` exists with ` sudo nano /etc/ssh/sshd_config.d/50-cloud-init.conf ` and add/edit this line:
100+
101+ ``` txt
102+ PasswordAuthentication no
103+ ```
104+
105+ Test and restart sshd:
106+
107+ ``` sh
108+ sudo sshd -t
109+ sudo systemctl restart ssh
110+ sudo systemctl status ssh
111+ ```
112+
113+ Disable root login by editing ` sudo nano /etc/ssh/sshd_config ` and add/edit this line:
114+
115+ ``` txt
116+ PermitRootLogin no
117+ ```
118+
119+ restart sshd:
120+
121+ ``` sh
122+ sudo systemctl restart ssh
123+ ```
124+
125+ Test ssh login from a different terminal (result should be "Permission denied"):
126+
127+ ``` sh
128+ ssh root@vps-ip
129+ ```
130+
131+ #### Firewall
132+
133+ Using UFW (Uncomplicated Firewall):
134+
135+ ``` sh
136+ sudo ufw status
137+ sudo ufw default deny incoming
138+ sudo ufw default allow outgoing
139+ sudo ufw allow ssh # Allow SSH before enabling firewall
140+ sudo ufw allow 80/tcp # Allow HTTP
141+ sudo ufw allow 443/tcp # Allow HTTPS
142+ ```
143+
144+ Enable firewall and type 'y' when prompted:
145+
146+ ``` sh
147+ sudo ufw enable
148+ sudo ufw status verbose
149+ ```
150+
151+ Change default SSH port:
152+
153+ ``` sh
154+ sudo nano /etc/ssh/sshd_config
155+ ```
156+
157+ ``` sh
158+ sudo ufw allow 666/tcp # changed Port 22 to Port 666
159+ sudo ufw delete allow 22/tcp
160+ sudo systemctl restart ssh
161+ ```
162+
163+ #### Updates
164+
165+ Activating unattended upgrades to ensure the server stays up-to-date:
166+
167+ ``` sh
168+ sudo apt install unattended-upgrades apt-listchanges
169+ ```
170+
171+ Run this and select "yes"
172+
173+ ``` sh
174+ sudo dpkg-reconfigure unattended-upgrades
175+ ```
176+
177+ Edit this file ` sudo nano /etc/apt/apt.conf.d/50unattended-upgrades ` and uncomment line:
178+
179+ ``` txt
180+ "${distro_id}:${distro_codename}-security";
181+ ```
182+
183+ As well as consider a reboot window e.g.:
184+
185+ ``` txt
186+ Unattended-Upgrade::Automatic-Reboot "true";
187+ Unattended-Upgrade::Automatic-Reboot-Time "04:00";
188+ ```
189+
190+ Test the unattended upgrades:
191+
192+ ``` sh
193+ sudo unattended-upgrades --dry-run
194+ sudo systemctl status unattended-upgrades
195+ ```
196+
197+ ## Checks
198+
199+ - [ ] SSH key authentication works
200+ - [ ] Password authentication is disabled
201+ - [ ] Root login is blocked
202+ - [ ] Firewall is active and configured
203+ - [ ] Automatic updates working
204+ - [ ] Application runs in production mode
205+ - [ ] SSL certificate valid
206+ - [ ] Backups are being created
207+
17208## Config System
18209
19210Update and clean up:
0 commit comments