1 file changed, +169, -22
e6d0b4fdocs: add instructions (wip)
README.md
+169, -22
+169, -22
@@ -2,29 +2,98 @@
2 2
3 3 # Instructions
4 4
5+After installing Debian, login as your non-root user and follow the steps bellow.
5 6
6 -# Description
7+#### Step 1: Installing `sudo`
7 8
8 -This project consists on setting up a virtual machine using Debian or Rocky ISO.
9+```
10+$ su -
11+# apt install sudo
12+# dpkg -l | grep sudo
13+```
9 14
10 -The dec
15+Reboot after this step with:
11 16
12 -debian vs rocky
13 -apparmos vs selinux
14 -ufw vs firewalld
15 -virtualbox vs utm
17+```
18+# sudo reboot
19+```
16 20
17 -password policies (/etc/pam.d/common-password):
18 -- `minlen`: defines minimum length
19 -- `ucredit`: uppercase (negative sign for at least, positive for maximum)
20 -- `lcredit`: lowercase (same as above)
21 -- `dcredit`: digit (same as above)
22 -- `maxrepeat`: maximum consecutive identical characters
23 -- `reject_username`: rejects passwords that contain the username
24 -- `difok`: defines how many characters must be different from old password
25 -- `enforce_for_root`: applies rules to root too
26 -
27 -sudo policies (/etc/sudoers.d/sudo_config):
21+#### Step 2: Create groups and add your user to them
22+
23+```
24+$ sudo addgroup user42
25+$ sudo adduser <username> user42
26+$ sudo adduser <username> sudo
27+```
28+
29+To verify group membership:
30+
31+```
32+$ getent group sudo user42
33+```
34+
35+#### Step 3: Install and configure SSH
36+
37+```
38+$ sudo apt install openssh-server
39+```
40+
41+To verify if it's running:
42+
43+```
44+$ sudo service ssh status
45+```
46+
47+Change default port and disable root login by editing:
48+
49+```
50+$ sudo vi /etc/ssh/sshd_config
51+```
52+
53+Find `#Port 22` and change it to `Port 4242` (notice the removal of the hash). \
54+Find `#PermitRootLogin prohibit-password` and change it to `PermitRootLogin no`.
55+
56+Restart the SSH service with:
57+
58+```
59+$ sudo service ssh restart
60+```
61+
62+If you want to connect to your virtual machine via SSH, you will need to port forward it in the settings of your VM in VirtualBox. \
63+Port forward host port 4241 to guest port 4242, then connect to it via:
64+
65+```
66+$ ssh <username>@localhost -p 4241
67+```
68+
69+#### Step 4: Install and add rules to UFW
70+
71+```
72+$ sudo apt install ufw
73+```
74+
75+Enable it:
76+
77+```
78+$ sudo ufw enable
79+```
80+
81+Allow ssh port:
82+
83+```
84+$ sudo ufw allow 4242
85+```
86+
87+Check its status:
88+
89+```
90+$ sudo ufw status
91+```
92+
93+#### Step 5: Change `sudo` policies
94+
95+Sudo policies are located at `/etc/sudoers.d/sudo_config`. \
96+The changes this project requires are:
28 97 - `passwd_tries`: total tries for entering the sudo password
29 98 - `badpass_message`: message that will show when the password failed
30 99 - `logfile`: path where the sudo logs will be stored
@@ -34,8 +103,63 @@ sudo policies (/etc/sudoers.d/sudo_config):
34103 - `requiretty`: tty becomes required
35104 - `secure_path`: specifies trusted PATH that sudo uses when searching for commands
36105
37 -script:
38106
107+```
108+$ cat /etc/sudoers.d/sudo_config
109+Defaults passwd_tries=3
110+Defaults badpass_message="Wrong password."
111+Defaults logfile="/var/log/sudo/sudo_config"
112+Defaults log_input
113+Defaults log_output
114+Defaults iolog_dir="/var/log/sudo"
115+Defaults requiretty
116+Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
117+```
118+
119+#### Step 6: Change password policies
120+
121+To change password policies, we need to change two files.
122+
123+First one is located at `/etc/login.defs`. \
124+Edit `PASS_MAX_DAYS` to 30, `PASS_MIN_DAYS` to 2 and keep `PASS_WARN_AGE` at 7.
125+
126+```
127+$ cat /etc/login.defs | grep ^PASS_
128+PASS_MAX_DAYS 30
129+PASS_MIN_DAYS 2
130+PASS_WARN_AGE 7
131+```
132+
133+For the second one, we will need to install `libpam-pwquality`.
134+
135+```
136+$ sudo apt install libpam-pwquality
137+```
138+
139+The file is located at `/etc/pam.d/common-password`. \
140+The policies we need to change are:
141+- `minlen`: defines minimum length
142+- `ucredit`: uppercase requirement (negative value = minimum required, positive value = maximum allowed)
143+- `lcredit`: lowercase requirement (same as above)
144+- `dcredit`: digit requirement (same as above)
145+- `maxrepeat`: maximum number of consecutive identical characters
146+- `usercheck`: rejects passwords that contain the username
147+- `difok`: specifies how many characters must differ from the previous password
148+- `enforce_for_root`: applies these rules to root user as well
149+
150+We don't want to apply `difok` to the root user, as stated in the subject. \
151+For that, we can utilize `pam_succeed_if.so`, that takes a condition and skips the next `requisite` if the condition is satisfied. The condition we care about is `uid=0` or `user=root`, both of them work since root's UID is 0.
152+
153+```
154+$ cat /etc/pam.d/common-password
155+...
156+password [success=1 default=ignore] pam_succeed_if.so uid=0
157+password requisite pam_pwquality.so retry=3 minlen=10 ucredit=-1 lcredit=-1 dcredit=-1 maxrepeat=3 usercheck=1 difok=7
158+password requisite pam_pwquality.so retry=3 minlen=10 ucredit=-1 lcredit=-1 dcredit=-1 maxrepeat=3 usercheck=1 enforce_for_root
159+...
160+```
161+
162+Script:
39163 ```bash
40164 #!/bin/bash
41165
@@ -67,7 +191,7 @@ mac_addr=$(ip link | grep "link/ether" | awk '{print $2}')
67191
68192 sudo_cmds=$(journalctl -q _COMM=sudo | grep COMMAND | wc -l)
69193
70 -echo "
194+wall "
71195 Architecture: $arch
72196 CPU physical: $cpu_phy
73197 vCPU: $cpu_vrt
@@ -80,13 +204,36 @@ Connections TCP: $tcp_conn ESTABLISHED
80204 User log: $user_log
81205 Network: IP $ip_addr ($mac_addr)
82206 Sudo: $sudo_cmds cmd
83 -" | wall
207+"
84208 ```
85209
210+# Description
211+
212+This project consists on setting up a virtual machine using Debian with a set of services and security features.
213+
214+This repository contains a [signature.txt](./signature.txt) of the virtual disk image.
215+
216+### Comparisons
217+
218+
219+| Feature | Personal choice | Alternative | Notes |
220+| ---------------- | ----------------- | ----------- | ----------------------------------------------------------------------------------------------- |
221+| Operating System | Debian | Rocky Linux | Debian is simple, stable and with extensive documentation; Rocky is more enterprise-oriented |
222+| Security Module | AppArmor | SELinux | AppArmor is simpler to configure; SELinux is more powerful but also more complex |
223+| Firewall | UFW | firewalld | UFW is user-friendly; firewalld provides more advanced rules for enterprises |
224+| Virtualization | VirtualBox | UTM | VirtualBox is widely used and well-documented; UTM is optimized for Apple Sillicon Macs |
225+
226+
227+
228+
229+
230+
231+
86232
87233 # Resources
88234
89 -- [Debian installation](https://www.debian.org/releases/stable/amd64/)
235+- [Debian installation guide](https://www.debian.org/releases/stable/amd64/)
236+- [`man chage`](https://manpages.debian.org/trixie/passwd/chage.1.en.html)
90237 - [`man cron`](https://manpages.debian.org/trixie/cron/cron.8.en.html)
91238 - [`man ufw`](https://manpages.debian.org/trixie/ufw/ufw.8.en.html)
92239 - [`man pam_pwquality`](https://manpages.debian.org/trixie/libpam-pwquality/pam_pwquality.8.en.html)