ServerHandbook live check: run log ------------------------------------------------------------------------------ Article https://serverhandbook.com/kb/ufw-firewall-ubuntu Check scripts/live/checks/ufw-firewall-ubuntu.mjs (sha256 713862633eb6e84f3afb6da9b27730f3d594afa390f6e943f91e7f304e1e9952) Ran at 2026-11-18T12:08:10Z (542 s) Result PASS, all 53 claims held Tested on System Ubuntu 24.04.4 LTS Kernel 6.8.0-138-generic Package ufw 0.36.2-6 Package iptables 1.8.10-3ubuntu2 Package openssh-server 1:9.6p1-3ubuntu13.18 Package linux-image-virtual 6.8.0-138.138 Setup A fresh Ubuntu 24.04 server as a provider hands it over (a rented cloud server with a public address), reached over SSH as a sudo user; the probes come from another computer on the internet. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (0) Packages upgraded (0) Packages removed (0) Services enabled at boot (0) Services disabled (0) Listening sockets opened (0) Listening sockets closed (0) Files added in /etc (0) Files changed in /etc (3) /etc/ufw/ufw.conf /etc/ufw/user.rules /etc/ufw/user6.rules Files removed from /etc (0) Disk used on / (includes logs written during the run): +7.6 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Audit: Lynis 3.1.7, the whole server, before the first step and after the last ------------------------------------------------------------------------------ Hardening index 60 -> 61 (Lynis's own score for this server; not a certification) Warnings 3 -> 2 Suggestions 42 -> 43 Resolved by the steps (1) FIRE-4512 iptables module(s) loaded, but no rules active New after the steps (1) FIRE-4513 Check iptables rules to see which rules are currently not used ------------------------------------------------------------------------------ Audit: nmap ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Check-your-server script (3 items): https://cdn.serverhandbook.com/check/ufw-firewall-ubuntu/ubuntu-24.04.4-20261118t120810z.sh SHA-256 e92957aedb028c8241b3c0d3a70dabf002dccb018e7b0dfd8b11d273440eb5a6 ------------------------------------------------------------------------------ On the stock server, before the first step: FAIL ufw is active FAIL SSH is allowed PASS ufw starts at boot After the last step: PASS ufw is active PASS SSH is allowed PASS ufw starts at boot ------------------------------------------------------------------------------ Claims (53), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 24.04 server box (web-server) starts 2. ok (setup) the test web server on port 80 answers from outside before any firewall 3. ok ufw is installed on a fresh server but inactive | Status: inactive 4. ok SSH listens on port 22 (the port the OpenSSH profile opens) | LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=917,fd=3),("systemd",pid=1,fd=62)) | LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=917,fd=4),("systemd",pid=1,fd=63)) 5. ok the defaults are already deny incoming (DROP), allow outgoing (ACCEPT) | DEFAULT_INPUT_POLICY="DROP" | DEFAULT_OUTPUT_POLICY="ACCEPT" | DEFAULT_FORWARD_POLICY="DROP" | DEFAULT_APPLICATION_POLICY="SKIP" 6. ok ufw app list shows the OpenSSH profile | Available applications: | OpenSSH 7. ok the OpenSSH profile opens 22/tcp | Profile: OpenSSH | Title: Secure shell server, an rshd replacement | Description: OpenSSH is a free implementation of the Secure Shell protocol. | | Port: | 22/tcp 8. ok ufw allow OpenSSH adds the rule for IPv4 and IPv6 while ufw is still off | Rules updated | Rules updated (v6) 9. ok ufw show added lists the saved rule before the firewall is on | Added user rules (see 'ufw status' for running firewall): | ufw allow OpenSSH 10. ok (setup) the reader’s open terminal (one kept SSH connection) opens 11. ok ufw enable warns "Command may disrupt existing ssh connections" and asks y/n | Command may disrupt existing ssh connections. Proceed with operation (y|n)? y | Firewall is active and enabled on system startup 12. ok after y: "Firewall is active and enabled on system startup" | Command may disrupt existing ssh connections. Proceed with operation (y|n)? y | Firewall is active and enabled on system startup 13. ok the open terminal still works after enable 14. ok a NEW SSH login from outside still gets in (step 4’s second terminal) 15. ok status verbose: active, deny incoming, allow outgoing, OpenSSH allowed for v4 and v6 | Status: active | Logging: on (low) | Default: deny (incoming), allow (outgoing), disabled (routed) | New profiles: skip | | To Action From | -- ------ ---- | 22/tcp (OpenSSH) ALLOW IN Anywhere | 22/tcp (OpenSSH (v6)) ALLOW IN Anywhere (v6) 16. ok logging is on (low) by default | Status: active | Logging: on (low) | Default: deny (incoming), allow (outgoing), disabled (routed) | New profiles: skip | | To Action From | -- ------ ---- | 22/tcp (OpenSSH) ALLOW IN Anywhere | 22/tcp (OpenSSH (v6)) ALLOW IN Anywhere (v6) 17. ok port 80 no longer answers from outside: the web server is still running but ufw drops the packets 18. ok (the test web server is still listening on port 80) | 1 19. ok /var/log/ufw.log records the drop: [UFW BLOCK] … DPT=80 … SYN | 2026-11-18T12:11:16.941994+00:00 shb-test kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:00:0a:87:2f:83:d2:74:7f:6e:37:e3:08:00 SRC=104.28.212.123 DST=203.0.113.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=29351 DF PROTO=TCP SPT=50965 DPT=80 WINDOW=65535 RES=0x00 SYN URGP=0 20. ok ufw allow 80/tcp: "Rule added" and "Rule added (v6)" | Rule added | Rule added (v6) 21. ok ufw allow 443/tcp adds both rules | Rule added | Rule added (v6) 22. ok port 80 answers from outside again at once, no reload needed 23. ok adding the same rule twice is harmless: "Skipping adding existing rule" | Skipping adding existing rule | Skipping adding existing rule (v6) 24. ok status numbered lists IPv4 and IPv6 rules as separate numbers | Status: active | | To Action From | -- ------ ---- | [ 1] OpenSSH ALLOW IN Anywhere | [ 2] 80/tcp ALLOW IN Anywhere | [ 3] 443/tcp ALLOW IN Anywhere | [ 4] OpenSSH (v6) ALLOW IN Anywhere (v6) | [ 5] 80/tcp (v6) ALLOW IN Anywhere (v6) | [ 6] 443/tcp (v6) ALLOW IN Anywhere (v6) 25. ok ufw delete allow 443/tcp removes the IPv4 AND the IPv6 rule | Rule deleted | Rule deleted (v6) 26. ok (found the number of the IPv4 80/tcp rule) | Status: active | | To Action From | -- ------ ---- | [ 1] OpenSSH ALLOW IN Anywhere | [ 2] 80/tcp ALLOW IN Anywhere | [ 3] OpenSSH (v6) ALLOW IN Anywhere (v6) | [ 4] 80/tcp (v6) ALLOW IN Anywhere (v6) 27. ok ufw delete asks first, then deletes ONE rule | Deleting: | allow 80/tcp | Proceed with operation (y|n)? y | Rule deleted 28. ok …the IPv6 80/tcp rule is still there, and the numbers below it moved up | Status: active | | To Action From | -- ------ ---- | [ 1] OpenSSH ALLOW IN Anywhere | [ 2] OpenSSH (v6) ALLOW IN Anywhere (v6) | [ 3] 80/tcp (v6) ALLOW IN Anywhere (v6) 29. ok deleting by rule text then removes the IPv6 leftover ("Could not delete non-existent rule" for the IPv4 one) | Could not delete non-existent rule | Rule deleted (v6) 30. ok ufw limit OpenSSH turns the allow rule into a limit rule: "Rule updated" | Rule updated | Rule updated (v6) 31. ok the limit rule is the kernel "recent" match: 6 new connections in 30 seconds from one address | -A ufw-user-input -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --set --name DEFAULT --mask 255.255.255.255 --rsource -m comment --comment "\'dapp_OpenSSH\'" | -A ufw-user-input -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 30 --hitcount 6 --name DEFAULT --mask 255.255.255.255 --rsource -m comment --comment "\'dapp_OpenSSH\'" -j ufw-user-limit | -A ufw-user-input -p tcp -m tcp --dport 22 -m comment --comment "\'dapp_OpenSSH\'" -j ufw-user-limit-accept 32. ok with the limit on, 5 new SSH connections in a row from one address reach the server and the 6th and 7th are dropped | true true true true true false false 33. ok the refused logins are logged as [UFW LIMIT BLOCK] | 2 34. ok 10 seconds later, while the address keeps trying, it is still refused 35. ok ufw allow OpenSSH turns the limit back into a plain allow: "Rule updated" | Rule updated | Rule updated (v6) 36. ok a new login gets in at once after that 37. ok the server reboots and answers over SSH again (port 22 allowed) | 22 38. ok port 80 answers from outside after the reboot (its rule was kept) 39. ok after a reboot ufw is active with the same rules | Status: active | | To Action From | -- ------ ---- | OpenSSH ALLOW Anywhere | 80/tcp ALLOW Anywhere | OpenSSH (v6) ALLOW Anywhere (v6) | 80/tcp (v6) ALLOW Anywhere (v6) 40. ok (SSH is allowed in the firewall at the end of the steps) | Status: active | | To Action From | -- ------ ---- | OpenSSH ALLOW Anywhere | 80/tcp ALLOW Anywhere | OpenSSH (v6) ALLOW Anywhere (v6) | 80/tcp (v6) ALLOW Anywhere (v6) 41. ok (ufw starts at boot) | enabled 42. ok /etc/ufw/before.rules accepts RELATED,ESTABLISHED traffic before any user rule | 25:-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT 43. ok (tested on) the box reports its OS, kernel and the version of 4 package(s) | PRETTY_NAME="Ubuntu 24.04.4 LTS" | VIRT=none | KERNEL=6.8.0-138-generic | PKG iptables 1.8.10-3ubuntu2 | PKG linux-image-virtual 6.8.0-138.138 | PKG openssh-server 1:9.6p1-3ubuntu13.18 | PKG ufw 0.36.2-6 44. ok ufw reset asks, backs up the rule files with a date, and leaves ufw inactive | Resetting all rules to installed defaults. This may disrupt existing ssh | connections. Proceed with operation (y|n)? y | Backing up 'user.rules' to '/etc/ufw/user.rules.20261118_121636' | Backing up 'before.rules' to '/etc/ufw/before.rules.20261118_121636' | Backing up 'after.rules' to '/etc/ufw/after.rules.20261118_121636' | Backing up 'user6.rules' to '/etc/ufw/user6.rules.20261118_121636' | Backing up 'before6.rules' to '/etc/ufw/before6.rules.20261118_121636' | Backing up 'after6.rules' to '/etc/ufw/after6.rules.20261118_121636' 45. ok after reset: Status: inactive and no rules | Status: inactive 46. ok (setup) a terminal is open before the mistake 47. ok ufw enable with no SSH rule still succeeds (the warning is the only guard) | Command may disrupt existing ssh connections. Proceed with operation (y|n)? y | Firewall is active and enabled on system startup 48. ok a NEW SSH login is now refused 49. ok the terminal that was already open keeps working 50. ok from that open terminal, ufw allow OpenSSH adds the rule to the running firewall: "Rule added" | Rule added | Rule added (v6) 51. ok new logins work again 52. ok ufw disable: "Firewall stopped and disabled on system startup" | Firewall stopped and disabled on system startup 53. ok port 80 answers again with the firewall off ------------------------------------------------------------------------------ Commands and what they printed (32) ------------------------------------------------------------------------------ $ sudo ufw status Status: inactive $ sudo ss -tlnp | grep ':22 ' LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=917,fd=3),("systemd",pid=1,fd=62)) LISTEN 0 4096 [::]:22 [::]:* users:(("sshd",pid=917,fd=4),("systemd",pid=1,fd=63)) $ grep '^DEFAULT_.*POLICY' /etc/default/ufw DEFAULT_INPUT_POLICY="DROP" DEFAULT_OUTPUT_POLICY="ACCEPT" DEFAULT_FORWARD_POLICY="DROP" DEFAULT_APPLICATION_POLICY="SKIP" $ sudo ufw app list Available applications: OpenSSH $ sudo ufw app info OpenSSH Profile: OpenSSH Title: Secure shell server, an rshd replacement Description: OpenSSH is a free implementation of the Secure Shell protocol. Port: 22/tcp $ sudo ufw allow OpenSSH Rules updated Rules updated (v6) $ sudo ufw show added Added user rules (see 'ufw status' for running firewall): ufw allow OpenSSH $ sudo ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)? y Firewall is active and enabled on system startup $ echo still here still here $ sudo ufw status verbose Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), disabled (routed) New profiles: skip To Action From -- ------ ---- 22/tcp (OpenSSH) ALLOW IN Anywhere 22/tcp (OpenSSH (v6)) ALLOW IN Anywhere (v6) $ sudo grep 'DPT=80 ' /var/log/ufw.log | tail -n 1 2026-11-18T12:11:16.941994+00:00 shb-test kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:00:0a:87:2f:83:d2:74:7f:6e:37:e3:08:00 SRC=104.28.212.123 DST=203.0.113.10 LEN=60 TOS=0x00 PREC=0x00 TTL=50 ID=29351 DF PROTO=TCP SPT=50965 DPT=80 WINDOW=65535 RES=0x00 SYN URGP=0 $ sudo ufw allow 80/tcp Rule added Rule added (v6) $ sudo ufw allow 443/tcp Rule added Rule added (v6) $ sudo ufw allow 80/tcp Skipping adding existing rule Skipping adding existing rule (v6) $ sudo ufw status numbered Status: active To Action From -- ------ ---- [ 1] OpenSSH ALLOW IN Anywhere [ 2] 80/tcp ALLOW IN Anywhere [ 3] 443/tcp ALLOW IN Anywhere [ 4] OpenSSH (v6) ALLOW IN Anywhere (v6) [ 5] 80/tcp (v6) ALLOW IN Anywhere (v6) [ 6] 443/tcp (v6) ALLOW IN Anywhere (v6) $ sudo ufw delete allow 443/tcp Rule deleted Rule deleted (v6) $ sudo ufw status numbered Status: active To Action From -- ------ ---- [ 1] OpenSSH ALLOW IN Anywhere [ 2] 80/tcp ALLOW IN Anywhere [ 3] OpenSSH (v6) ALLOW IN Anywhere (v6) [ 4] 80/tcp (v6) ALLOW IN Anywhere (v6) $ sudo ufw delete 2 Deleting: allow 80/tcp Proceed with operation (y|n)? y Rule deleted $ sudo ufw status numbered Status: active To Action From -- ------ ---- [ 1] OpenSSH ALLOW IN Anywhere [ 2] OpenSSH (v6) ALLOW IN Anywhere (v6) [ 3] 80/tcp (v6) ALLOW IN Anywhere (v6) $ sudo ufw delete allow 80/tcp Could not delete non-existent rule Rule deleted (v6) $ sudo ufw limit OpenSSH Rule updated Rule updated (v6) $ sudo iptables -S ufw-user-input | grep -- '--dport 22' -A ufw-user-input -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --set --name DEFAULT --mask 255.255.255.255 --rsource -m comment --comment "\'dapp_OpenSSH\'" -A ufw-user-input -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 30 --hitcount 6 --name DEFAULT --mask 255.255.255.255 --rsource -m comment --comment "\'dapp_OpenSSH\'" -j ufw-user-limit -A ufw-user-input -p tcp -m tcp --dport 22 -m comment --comment "\'dapp_OpenSSH\'" -j ufw-user-limit-accept $ sudo grep -c 'UFW LIMIT BLOCK' /var/log/ufw.log 2 $ sudo ufw allow OpenSSH Rule updated Rule updated (v6) $ sudo ufw status Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere 80/tcp ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 80/tcp (v6) ALLOW Anywhere (v6) $ sudo grep -n 'ctstate RELATED,ESTABLISHED -j ACCEPT' /etc/ufw/before.rules | head -n 1 25:-A ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT $ sudo ufw reset Resetting all rules to installed defaults. This may disrupt existing ssh connections. Proceed with operation (y|n)? y Backing up 'user.rules' to '/etc/ufw/user.rules.20261118_121636' Backing up 'before.rules' to '/etc/ufw/before.rules.20261118_121636' Backing up 'after.rules' to '/etc/ufw/after.rules.20261118_121636' Backing up 'user6.rules' to '/etc/ufw/user6.rules.20261118_121636' Backing up 'before6.rules' to '/etc/ufw/before6.rules.20261118_121636' Backing up 'after6.rules' to '/etc/ufw/after6.rules.20261118_121636' $ sudo ufw status Status: inactive $ sudo ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)? y Firewall is active and enabled on system startup $ echo still here still here $ sudo ufw allow OpenSSH Rule added Rule added (v6) $ sudo ufw disable Firewall stopped and disabled on system startup ------------------------------------------------------------------------------ The check-your-server script, its full screen before the steps ------------------------------------------------------------------------------ ServerHandbook check, ufw-firewall-ubuntu (proved 2026-11-18) FAIL ufw is active fix: https://serverhandbook.com/kb/ufw-firewall-ubuntu#step-3-enable FAIL SSH is allowed fix: https://serverhandbook.com/kb/ufw-firewall-ubuntu#step-1-allow-ssh PASS ufw starts at boot 1 passed, 2 failed To fix a FAIL, follow the steps in https://serverhandbook.com/kb/ufw-firewall-ubuntu ------------------------------------------------------------------------------ The check-your-server script, its full screen after the steps ------------------------------------------------------------------------------ ServerHandbook check, ufw-firewall-ubuntu (proved 2026-11-18) PASS ufw is active PASS SSH is allowed PASS ufw starts at boot 3 passed, 0 failed ------------------------------------------------------------------------------ lynis: its full screen before the first step ------------------------------------------------------------------------------ [ Lynis 3.1.7 ] ################################################################################ Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License. See the LICENSE file for details about using this software. 2007-2025, CISOfy - https://cisofy.com/lynis/ Enterprise support available (compliance, plugins, interface and tools) ################################################################################ [+] Initializing program ------------------------------------ - Detecting OS...  [ DONE ] - Checking profiles... [ DONE ] --------------------------------------------------- Program version: 3.1.7 Operating system: Linux Operating system name: Ubuntu Operating system version: 24.04 End-of-life: NO Kernel version: 6.8.0 Hardware platform: x86_64 Hostname: web-server --------------------------------------------------- Profiles: /tmp/shb-audit/lynis/default.prf Log file: /dev/null Report file: /tmp/shb-audit/report.dat Report version: 1.0 Plugin directory: ./plugins --------------------------------------------------- Auditor: [Not Specified] Language: en Test category: all Test group: all --------------------------------------------------- - Program update status...  [ NO UPDATE ] [+] System tools ------------------------------------ - Scanning available tools... - Checking system binaries... [+] Plugins (phase 1) ------------------------------------ Note: plugins have more extensive tests and may take several minutes to complete   - Plugins enabled [ NONE ] [+] Boot and services ------------------------------------ - Service Manager [ systemd ] - Checking UEFI boot [ DISABLED ] - Checking presence GRUB2 [ FOUND ] - Checking for password protection [ NONE ] - Check running services (systemctl) [ DONE ] Result: found 19 running services - Check enabled services at boot (systemctl) [ DONE ] Result: found 45 enabled services - Check startup files (permissions) [ OK ] - Running 'systemd-analyze security' Unit name (exposure value) and predicate -------------------------------- - acpid.service (value=9.6) [ UNSAFE ] - atd.service (value=9.6) [ UNSAFE ] - cron.service (value=9.6) [ UNSAFE ] - dbus.service (value=9.5) [ UNSAFE ] - dm-event.service (value=9.5) [ UNSAFE ] - dmesg.service (value=9.6) [ UNSAFE ] - emergency.service (value=9.5) [ UNSAFE ] - getty@tty1.service (value=9.6) [ UNSAFE ] - iscsid.service (value=9.5) [ UNSAFE ] - lvm2-lvmpolld.service (value=9.5) [ UNSAFE ] - multipathd.service (value=9.5) [ UNSAFE ] - networkd-dispatcher.service (value=9.6) [ UNSAFE ] - open-vm-tools.service (value=9.5) [ UNSAFE ] - plymouth-start.service (value=9.5) [ UNSAFE ] - qemu-guest-agent.service (value=9.6) [ UNSAFE ] - rc-local.service (value=9.6) [ UNSAFE ] - rescue.service (value=9.5) [ UNSAFE ] - rsyslog.service (value=6.3) [ MEDIUM ] - serial-getty@ttyS0.service (value=9.6) [ UNSAFE ] - snapd.service (value=9.9) [ UNSAFE ] - ssh.service (value=9.6) [ UNSAFE ] - systemd-ask-password-console.service (value=9.4) [ UNSAFE ] - systemd-ask-password-plymouth.service (value=9.5) [ UNSAFE ] - systemd-ask-password-wall.service (value=9.4) [ UNSAFE ] - systemd-bsod.service (value=9.5) [ UNSAFE ] - systemd-fsckd.service (value=9.5) [ UNSAFE ] - systemd-initctl.service (value=9.4) [ UNSAFE ] - systemd-journald.service (value=4.3) [ PROTECTED ] - systemd-logind.service (value=2.8) [ PROTECTED ] - systemd-networkd.service (value=2.6) [ PROTECTED ] - systemd-resolved.service (value=2.2) [ PROTECTED ] - systemd-rfkill.service (value=9.4) [ UNSAFE ] - systemd-timesyncd.service (value=2.1) [ PROTECTED ] - systemd-udevd.service (value=7.2) [ MEDIUM ] - tpm-udev.service (value=9.6) [ UNSAFE ] - ubuntu-advantage.service (value=9.6) [ UNSAFE ] - unattended-upgrades.service (value=9.6) [ UNSAFE ] - user@0.service (value=9.8) [ UNSAFE ] - user@1000.service (value=9.4) [ UNSAFE ] - uuidd.service (value=5.8) [ MEDIUM ] - vgauth.service (value=9.5) [ UNSAFE ] [+] Kernel ------------------------------------ - Checking default runlevel [ runlevel 5 ] - Checking CPU support (NX/PAE) CPU support: PAE and/or NoeXecute supported [ FOUND ] - Checking kernel version and release [ DONE ] - Checking kernel type [ DONE ] - Checking loaded kernel modules [ DONE ] Found 56 active modules - Checking Linux kernel configuration file [ FOUND ] - Checking default I/O kernel scheduler [ NOT FOUND ] - Checking for available kernel update [ OK ] - Checking core dumps configuration - configuration in systemd conf files [ DEFAULT ] - configuration in /etc/profile [ DEFAULT ] - 'hard' configuration in /etc/security/limits.conf [ DEFAULT ] - 'soft' configuration in /etc/security/limits.conf [ DEFAULT ] - Checking setuid core dumps configuration [ PROTECTED ] - Check if reboot is needed [ NO ] [+] Memory and Processes ------------------------------------ - Checking /proc/meminfo [ FOUND ] - Searching for dead/zombie processes [ NOT FOUND ] - Searching for IO waiting processes [ NOT FOUND ] - Search prelink tooling [ NOT FOUND ] [+] Users, Groups and Authentication ------------------------------------ - Administrator accounts [ OK ] - Unique UIDs [ OK ] - Consistency of group files (grpck) [ OK ] - Unique group IDs [ OK ] - Unique group names [ OK ] - Password file consistency [ OK ] - Password hashing methods [ OK ] - Checking password hashing rounds [ DISABLED ] - Query system users (non daemons) [ DONE ] - NIS+ authentication support [ NOT ENABLED ] - NIS authentication support [ NOT ENABLED ] - Sudoers file(s) [ FOUND ] - Permissions for directory: /etc/sudoers.d [ OK ] - Permissions for: /etc/sudoers [ OK ] - Permissions for: /etc/sudoers.d/90-shb-automation [ OK ] - Permissions for: /etc/sudoers.d/README [ OK ] - Permissions for: /etc/sudoers.d/90-cloud-init-users [ OK ] - PAM password strength tools [ SUGGESTION ] - PAM configuration files (pam.conf) [ FOUND ] - PAM configuration files (pam.d) [ FOUND ] - PAM modules [ FOUND ] - LDAP module in PAM [ NOT FOUND ] - Accounts without expire date [ OK ] - Accounts without password [ OK ] - Locked accounts [ FOUND ] - Checking user password aging (minimum) [ DISABLED ] - User password aging (maximum) [ DISABLED ] - Checking expired passwords [ OK ] - Checking Linux single user mode authentication [ OK ] - Determining default umask - umask (/etc/profile) [ NOT FOUND ] - umask (/etc/login.defs) [ SUGGESTION ] - LDAP authentication support [ NOT ENABLED ] - Logging failed login attempts [ ENABLED ] [+] Kerberos ------------------------------------ - Check for Kerberos KDC and principals [ NOT FOUND ] [+] Shells ------------------------------------ - Checking shells from /etc/shells Result: found 9 shells (valid shells: 9). - Session timeout settings/tools [ NONE ] - Checking default umask values - Checking default umask in /etc/bash.bashrc [ NONE ] - Checking default umask in /etc/profile [ NONE ] [+] File systems ------------------------------------ - Checking mount points - Checking /home mount point [ SUGGESTION ] - Checking /tmp mount point [ SUGGESTION ] - Checking /var mount point [ SUGGESTION ] - Query swap partitions (fstab) [ NONE ] - Testing swap partitions [ OK ] - Testing /proc mount (hidepid) [ SUGGESTION ] - Checking for old files in /tmp [ OK ] - Checking /tmp sticky bit [ OK ] - Checking /var/tmp sticky bit [ OK ] - ACL support root file system [ ENABLED ] - Mount options of / [ OK ] - Mount options of /dev [ PARTIALLY HARDENED ] - Mount options of /dev/shm [ PARTIALLY HARDENED ] - Mount options of /run [ HARDENED ] - Total without nodev:5 noexec:8 nosuid:3 ro or noexec (W^X): 8 of total 23 - Disable kernel support of some filesystems [+] USB Devices ------------------------------------ - Checking usb-storage driver (modprobe config) [ NOT DISABLED ] - Checking USB devices authorization [ ENABLED ] - Checking USBGuard [ NOT FOUND ] [+] Storage ------------------------------------ - Checking firewire ohci driver (modprobe config) [ DISABLED ] [+] NFS ------------------------------------ - Check running NFS daemon [ NOT FOUND ] [+] Name services ------------------------------------ - Checking search domains [ FOUND ] - Checking /etc/resolv.conf options [ FOUND ] - Searching DNS domain name [ UNKNOWN ] - Checking /etc/hosts - Duplicate entries in hosts file [ NONE ] - Presence of configured hostname in /etc/hosts [ NOT FOUND ] - Hostname mapped to localhost [ NOT FOUND ] - Localhost mapping to IP address [ OK ] [+] Ports and packages ------------------------------------ - Searching package managers - Searching dpkg package manager [ FOUND ] - Querying package manager - Query unpurged packages [ NONE ] - Checking security repository in sources.list file or directory [ WARNING ] - Checking APT package database [ OK ] - Checking vulnerable packages [ WARNING ] [WARNING]: Test PKGS-7392 had a long execution: 20.828809 seconds - Checking upgradeable packages [ SKIPPED ] - Checking package audit tool [ INSTALLED ] Found: apt-get - Toolkit for automatic upgrades (unattended-upgrade) [ FOUND ] [+] Networking ------------------------------------ - Checking IPv6 configuration [ ENABLED ] Configuration method [ AUTO ] IPv6 only [ NO ] - Checking configured nameservers - Testing nameservers Nameserver: 127.0.0.53 [ OK ] - DNSSEC supported (systemd-resolved) [ UNKNOWN ] - Checking default gateway [ DONE ] - Getting listening ports (TCP/UDP) [ DONE ] - Checking promiscuous interfaces [ OK ] - Checking waiting connections [ OK ] - Checking status DHCP client [ NOT ACTIVE ] - Checking for ARP monitoring software [ NOT FOUND ] - Uncommon network protocols [ 0 ] [+] Printers and Spools ------------------------------------ - Checking cups daemon [ NOT FOUND ] - Checking lp daemon [ NOT RUNNING ] [+] Software: e-mail and messaging ------------------------------------ [+] Software: firewalls ------------------------------------ - Checking iptables kernel module [ FOUND ] - Checking iptables policies of chains [ FOUND ] - Chain INPUT (table: filter, target: ACCEPT) [ ACCEPT ] - Chain INPUT (table: security, target: ACCEPT) [ ACCEPT ] - Checking for empty ruleset [ WARNING ] - Checking for unused rules [ OK ] - Checking host based firewall [ ACTIVE ] [+] Software: webserver ------------------------------------ - Checking Apache [ NOT FOUND ] - Checking nginx [ NOT FOUND ] [+] SSH Support ------------------------------------ - Checking running SSH daemon [ FOUND ] - Searching SSH configuration [ FOUND ] - OpenSSH option: AllowTcpForwarding [ SUGGESTION ] - OpenSSH option: ClientAliveCountMax [ SUGGESTION ] - OpenSSH option: ClientAliveInterval [ OK ] - OpenSSH option: FingerprintHash [ OK ] - OpenSSH option: GatewayPorts [ OK ] - OpenSSH option: IgnoreRhosts [ OK ] - OpenSSH option: LoginGraceTime [ OK ] - OpenSSH option: LogLevel [ SUGGESTION ] - OpenSSH option: MaxAuthTries [ SUGGESTION ] - OpenSSH option: MaxSessions [ SUGGESTION ] - OpenSSH option: PermitRootLogin [ OK ] - OpenSSH option: PermitUserEnvironment [ OK ] - OpenSSH option: PermitTunnel [ OK ] - OpenSSH option: Port [ SUGGESTION ] - OpenSSH option: PrintLastLog [ OK ] - OpenSSH option: StrictModes [ OK ] - OpenSSH option: TCPKeepAlive [ SUGGESTION ] - OpenSSH option: UseDNS [ OK ] - OpenSSH option: X11Forwarding [ SUGGESTION ] - OpenSSH option: AllowAgentForwarding [ SUGGESTION ] - OpenSSH option: AllowUsers [ NOT FOUND ] - OpenSSH option: AllowGroups [ NOT FOUND ] [+] SNMP Support ------------------------------------ - Checking running SNMP daemon [ NOT FOUND ] [+] Databases ------------------------------------ No database engines found [+] LDAP Services ------------------------------------ - Checking OpenLDAP instance [ NOT FOUND ] [+] PHP ------------------------------------ - Checking PHP [ NOT FOUND ] [+] Squid Support ------------------------------------ - Checking running Squid daemon [ NOT FOUND ] [+] Logging and files ------------------------------------ - Checking for a running log daemon [ OK ] - Checking Syslog-NG status [ NOT FOUND ] - Checking systemd journal status [ FOUND ] - Checking Metalog status [ NOT FOUND ] - Checking RSyslog status [ FOUND ] - Checking RFC 3195 daemon status [ NOT FOUND ] - Checking minilogd instances [ NOT FOUND ] - Checking wazuh-agent daemon status [ NOT FOUND ] - Checking logrotate presence [ OK ] - Checking remote logging [ NOT ENABLED ] - Checking log directories (static list) [ DONE ] - Checking open log files [ DONE ] - Checking deleted files in use [ DONE ] [+] Insecure services ------------------------------------ - Installed inetd package [ NOT FOUND ] - Installed xinetd package [ OK ] - xinetd status [ NOT ACTIVE ] - Installed rsh client package [ OK ] - Installed rsh server package [ OK ] - Installed telnet client package [ OK ] - Installed telnet server package [ NOT FOUND ] - Checking NIS client installation [ OK ] - Checking NIS server installation [ OK ] - Checking TFTP client installation [ OK ] - Checking TFTP server installation [ OK ] [+] Banners and identification ------------------------------------ - /etc/issue [ FOUND ] - /etc/issue contents [ WEAK ] - /etc/issue.net [ FOUND ] - /etc/issue.net contents [ WEAK ] [+] Scheduled tasks ------------------------------------ - Checking crontab and cronjob files [ DONE ] - Checking atd status [ RUNNING ] - Checking at users [ DONE ] - Checking at jobs [ NONE ] [+] Accounting ------------------------------------ - Checking accounting information [ NOT FOUND ] - Checking sysstat accounting data [ DISABLED ] - Checking auditd [ NOT FOUND ] [+] Time and Synchronization ------------------------------------ - NTP daemon found: systemd (timesyncd) [ FOUND ] - Checking for a running NTP daemon or client [ OK ] - Last time synchronization [ 25s ] [+] Cryptography ------------------------------------ - Checking for expired SSL certificates [0/123] [ NONE ] - Found 0 encrypted and 0 unencrypted swap devices in use. [ OK ] - Kernel entropy is sufficient [ YES ] - HW RNG & rngd [ NO ] - SW prng [ NO ] - MOR variable not found [ WEAK ] [+] Virtualization ------------------------------------ [+] Containers ------------------------------------ [+] Security frameworks ------------------------------------ - Checking presence AppArmor [ FOUND ] - Checking AppArmor status [ ENABLED ] Found 35 unconfined processes - Checking presence SELinux [ NOT FOUND ] - Checking presence TOMOYO Linux [ NOT FOUND ] - Checking presence grsecurity [ NOT FOUND ] - Checking for implemented MAC framework [ OK ] [+] Software: file integrity ------------------------------------ - Checking file integrity tools - dm-integrity (status) [ DISABLED ] - dm-verity (status) [ DISABLED ] - Checking presence integrity tool [ NOT FOUND ] [+] Software: System tooling ------------------------------------ - Checking automation tooling - Automation tooling [ NOT FOUND ] - Checking for IDS/IPS tooling [ NONE ] [+] Software: Malware ------------------------------------ - Malware software components [ NOT FOUND ] [+] File Permissions ------------------------------------ - Starting file permissions check File: /boot/grub/grub.cfg [ OK ] File: /etc/at.deny [ SUGGESTION ] File: /etc/crontab [ SUGGESTION ] File: /etc/group [ OK ] File: /etc/group- [ OK ] File: /etc/hosts.allow [ OK ] File: /etc/hosts.deny [ OK ] File: /etc/issue [ OK ] File: /etc/issue.net [ OK ] File: /etc/passwd [ OK ] File: /etc/passwd- [ OK ] File: /etc/ssh/sshd_config [ SUGGESTION ] Directory: /root/.ssh [ OK ] Directory: /etc/cron.d [ SUGGESTION ] Directory: /etc/cron.daily [ SUGGESTION ] Directory: /etc/cron.hourly [ SUGGESTION ] Directory: /etc/cron.weekly [ SUGGESTION ] Directory: /etc/cron.monthly [ SUGGESTION ] [+] Home directories ------------------------------------ - Permissions of home directories [ OK ] - Ownership of home directories [ OK ] - Checking shell history files [ OK ] [+] Kernel Hardening ------------------------------------ - Comparing sysctl key pairs with scan profile - dev.tty.ldisc_autoload (exp: 0) [ DIFFERENT ] - fs.protected_fifos (exp: 2) [ DIFFERENT ] - fs.protected_hardlinks (exp: 1) [ OK ] - fs.protected_regular (exp: 2) [ OK ] - fs.protected_symlinks (exp: 1) [ OK ] - fs.suid_dumpable (exp: 0) [ DIFFERENT ] - kernel.core_uses_pid (exp: 1) [ DIFFERENT ] - kernel.ctrl-alt-del (exp: 0) [ OK ] - kernel.dmesg_restrict (exp: 1) [ OK ] - kernel.kptr_restrict (exp: 2) [ DIFFERENT ] - kernel.modules_disabled (exp: 1) [ DIFFERENT ] - kernel.perf_event_paranoid (exp: 2 3 4) [ OK ] - kernel.randomize_va_space (exp: 2) [ OK ] - kernel.sysrq (exp: 0) [ DIFFERENT ] - kernel.unprivileged_bpf_disabled (exp: 1) [ DIFFERENT ] - kernel.yama.ptrace_scope (exp: 1 2 3) [ OK ] - net.core.bpf_jit_harden (exp: 2) [ DIFFERENT ] - net.ipv4.conf.all.accept_redirects (exp: 0) [ DIFFERENT ] - net.ipv4.conf.all.accept_source_route (exp: 0) [ OK ] - net.ipv4.conf.all.bootp_relay (exp: 0) [ OK ] - net.ipv4.conf.all.forwarding (exp: 0) [ OK ] - net.ipv4.conf.all.log_martians (exp: 1) [ DIFFERENT ] - net.ipv4.conf.all.mc_forwarding (exp: 0) [ OK ] - net.ipv4.conf.all.proxy_arp (exp: 0) [ OK ] - net.ipv4.conf.all.rp_filter (exp: 1) [ DIFFERENT ] - net.ipv4.conf.all.send_redirects (exp: 0) [ DIFFERENT ] - net.ipv4.conf.default.accept_redirects (exp: 0) [ DIFFERENT ] - net.ipv4.conf.default.accept_source_route (exp: 0) [ DIFFERENT ] - net.ipv4.conf.default.log_martians (exp: 1) [ DIFFERENT ] - net.ipv4.icmp_echo_ignore_broadcasts (exp: 1) [ OK ] - net.ipv4.icmp_ignore_bogus_error_responses (exp: 1) [ OK ] - net.ipv4.tcp_syncookies (exp: 1) [ OK ] - net.ipv4.tcp_timestamps (exp: 0 1) [ OK ] - net.ipv6.conf.all.accept_redirects (exp: 0) [ DIFFERENT ] - net.ipv6.conf.all.accept_source_route (exp: 0) [ OK ] - net.ipv6.conf.default.accept_redirects (exp: 0) [ DIFFERENT ] - net.ipv6.conf.default.accept_source_route (exp: 0) [ OK ] [+] Hardening ------------------------------------ - Installed compiler(s) [ NOT FOUND ] - Installed malware scanner [ NOT FOUND ] - Non-native binary formats [ FOUND ] [+] Custom tests ------------------------------------ - Running custom tests...  [ NONE ] [+] Plugins (phase 2) ------------------------------------ ================================================================================ -[ Lynis 3.1.7 Results ]- Great, no warnings No suggestions ================================================================================ Lynis security scan details: Scan mode: Normal [▆] Forensics [ ] Integration [ ] Pentest [ ] Lynis modules: - Compliance status [?] - Security audit [V] - Vulnerability scan [V] Details: Hardening index : 60 [############ ] Tests performed : 257 Plugins enabled : 0 Software components: - Firewall [V] - Intrusion software [X] - Malware scanner [X] Files: - Test and debug information : /dev/null - Report data : /tmp/shb-audit/report.dat ================================================================================ Lynis 3.1.7 Auditing, system hardening, and compliance for UNIX-based systems (Linux, macOS, BSD, and others) 2007-2025, CISOfy - https://cisofy.com/lynis/ Enterprise support available (compliance, plugins, interface and tools) ================================================================================ [TIP]: Enhance Lynis audits by adding your settings to custom.prf (see /tmp/shb-audit/lynis/default.prf for all settings) ------------------------------------------------------------------------------ lynis: its full screen after the last step ------------------------------------------------------------------------------ [ Lynis 3.1.7 ] ################################################################################ Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under the terms of the GNU General Public License. See the LICENSE file for details about using this software. 2007-2025, CISOfy - https://cisofy.com/lynis/ Enterprise support available (compliance, plugins, interface and tools) ################################################################################ [+] Initializing program ------------------------------------ - Detecting OS...  [ DONE ] - Checking profiles... [ DONE ] --------------------------------------------------- Program version: 3.1.7 Operating system: Linux Operating system name: Ubuntu Operating system version: 24.04 End-of-life: NO Kernel version: 6.8.0 Hardware platform: x86_64 Hostname: web-server --------------------------------------------------- Profiles: /tmp/shb-audit/lynis/default.prf Log file: /dev/null Report file: /tmp/shb-audit/report.dat Report version: 1.0 Plugin directory: ./plugins --------------------------------------------------- Auditor: [Not Specified] Language: en Test category: all Test group: all --------------------------------------------------- - Program update status...  [ NO UPDATE ] [+] System tools ------------------------------------ - Scanning available tools... - Checking system binaries... [+] Plugins (phase 1) ------------------------------------ Note: plugins have more extensive tests and may take several minutes to complete   - Plugins enabled [ NONE ] [+] Boot and services ------------------------------------ - Service Manager [ systemd ] - Checking UEFI boot [ DISABLED ] - Checking presence GRUB2 [ FOUND ] - Checking for password protection [ NONE ] - Check running services (systemctl) [ DONE ] Result: found 18 running services - Check enabled services at boot (systemctl) [ DONE ] Result: found 45 enabled services - Check startup files (permissions) [ OK ] - Running 'systemd-analyze security' Unit name (exposure value) and predicate -------------------------------- - acpid.service (value=9.6) [ UNSAFE ] - atd.service (value=9.6) [ UNSAFE ] - cron.service (value=9.6) [ UNSAFE ] - dbus.service (value=9.5) [ UNSAFE ] - dm-event.service (value=9.5) [ UNSAFE ] - dmesg.service (value=9.6) [ UNSAFE ] - emergency.service (value=9.5) [ UNSAFE ] - getty@tty1.service (value=9.6) [ UNSAFE ] - iscsid.service (value=9.5) [ UNSAFE ] - lvm2-lvmpolld.service (value=9.5) [ UNSAFE ] - multipathd.service (value=9.5) [ UNSAFE ] - networkd-dispatcher.service (value=9.6) [ UNSAFE ] - open-vm-tools.service (value=9.5) [ UNSAFE ] - plymouth-start.service (value=9.5) [ UNSAFE ] - qemu-guest-agent.service (value=9.6) [ UNSAFE ] - rc-local.service (value=9.6) [ UNSAFE ] - rescue.service (value=9.5) [ UNSAFE ] - rsyslog.service (value=6.3) [ MEDIUM ] - serial-getty@ttyS0.service (value=9.6) [ UNSAFE ] - snapd.service (value=9.9) [ UNSAFE ] - ssh.service (value=9.6) [ UNSAFE ] - systemd-ask-password-console.service (value=9.4) [ UNSAFE ] - systemd-ask-password-plymouth.service (value=9.5) [ UNSAFE ] - systemd-ask-password-wall.service (value=9.4) [ UNSAFE ] - systemd-bsod.service (value=9.5) [ UNSAFE ] - systemd-fsckd.service (value=9.5) [ UNSAFE ] - systemd-initctl.service (value=9.4) [ UNSAFE ] - systemd-journald.service (value=4.3) [ PROTECTED ] - systemd-logind.service (value=2.8) [ PROTECTED ] - systemd-networkd.service (value=2.6) [ PROTECTED ] - systemd-resolved.service (value=2.2) [ PROTECTED ] - systemd-rfkill.service (value=9.4) [ UNSAFE ] - systemd-timesyncd.service (value=2.1) [ PROTECTED ] - systemd-udevd.service (value=7.2) [ MEDIUM ] - tpm-udev.service (value=9.6) [ UNSAFE ] - ubuntu-advantage.service (value=9.6) [ UNSAFE ] - unattended-upgrades.service (value=9.6) [ UNSAFE ] - user@0.service (value=9.8) [ UNSAFE ] - user@1000.service (value=9.4) [ UNSAFE ] - uuidd.service (value=5.8) [ MEDIUM ] - vgauth.service (value=9.5) [ UNSAFE ] [+] Kernel ------------------------------------ - Checking default runlevel [ runlevel 5 ] - Checking CPU support (NX/PAE) CPU support: PAE and/or NoeXecute supported [ FOUND ] - Checking kernel version and release [ DONE ] - Checking kernel type [ DONE ] - Checking loaded kernel modules [ DONE ] Found 77 active modules - Checking Linux kernel configuration file [ FOUND ] - Checking default I/O kernel scheduler [ NOT FOUND ] - Checking for available kernel update [ OK ] - Checking core dumps configuration - configuration in systemd conf files [ DEFAULT ] - configuration in /etc/profile [ DEFAULT ] - 'hard' configuration in /etc/security/limits.conf [ DEFAULT ] - 'soft' configuration in /etc/security/limits.conf [ DEFAULT ] - Checking setuid core dumps configuration [ PROTECTED ] - Check if reboot is needed [ NO ] [+] Memory and Processes ------------------------------------ - Checking /proc/meminfo [ FOUND ] - Searching for dead/zombie processes [ NOT FOUND ] - Searching for IO waiting processes [ NOT FOUND ] - Search prelink tooling [ NOT FOUND ] [+] Users, Groups and Authentication ------------------------------------ - Administrator accounts [ OK ] - Unique UIDs [ OK ] - Consistency of group files (grpck) [ OK ] - Unique group IDs [ OK ] - Unique group names [ OK ] - Password file consistency [ OK ] - Password hashing methods [ OK ] - Checking password hashing rounds [ DISABLED ] - Query system users (non daemons) [ DONE ] - NIS+ authentication support [ NOT ENABLED ] - NIS authentication support [ NOT ENABLED ] - Sudoers file(s) [ FOUND ] - Permissions for directory: /etc/sudoers.d [ OK ] - Permissions for: /etc/sudoers [ OK ] - Permissions for: /etc/sudoers.d/90-shb-automation [ OK ] - Permissions for: /etc/sudoers.d/README [ OK ] - Permissions for: /etc/sudoers.d/90-cloud-init-users [ OK ] - PAM password strength tools [ SUGGESTION ] - PAM configuration files (pam.conf) [ FOUND ] - PAM configuration files (pam.d) [ FOUND ] - PAM modules [ FOUND ] - LDAP module in PAM [ NOT FOUND ] - Accounts without expire date [ OK ] - Accounts without password [ OK ] - Locked accounts [ FOUND ] - Checking user password aging (minimum) [ DISABLED ] - User password aging (maximum) [ DISABLED ] - Checking expired passwords [ OK ] - Checking Linux single user mode authentication [ OK ] - Determining default umask - umask (/etc/profile) [ NOT FOUND ] - umask (/etc/login.defs) [ SUGGESTION ] - LDAP authentication support [ NOT ENABLED ] - Logging failed login attempts [ ENABLED ] [+] Kerberos ------------------------------------ - Check for Kerberos KDC and principals [ NOT FOUND ] [+] Shells ------------------------------------ - Checking shells from /etc/shells Result: found 9 shells (valid shells: 9). - Session timeout settings/tools [ NONE ] - Checking default umask values - Checking default umask in /etc/bash.bashrc [ NONE ] - Checking default umask in /etc/profile [ NONE ] [+] File systems ------------------------------------ - Checking mount points - Checking /home mount point [ SUGGESTION ] - Checking /tmp mount point [ SUGGESTION ] - Checking /var mount point [ SUGGESTION ] - Query swap partitions (fstab) [ NONE ] - Testing swap partitions [ OK ] - Testing /proc mount (hidepid) [ SUGGESTION ] - Checking for old files in /tmp [ OK ] - Checking /tmp sticky bit [ OK ] - Checking /var/tmp sticky bit [ OK ] - ACL support root file system [ ENABLED ] - Mount options of / [ OK ] - Mount options of /dev [ PARTIALLY HARDENED ] - Mount options of /dev/shm [ PARTIALLY HARDENED ] - Mount options of /run [ HARDENED ] - Total without nodev:5 noexec:8 nosuid:3 ro or noexec (W^X): 8 of total 23 - Disable kernel support of some filesystems [+] USB Devices ------------------------------------ - Checking usb-storage driver (modprobe config) [ NOT DISABLED ] - Checking USB devices authorization [ ENABLED ] - Checking USBGuard [ NOT FOUND ] [+] Storage ------------------------------------ - Checking firewire ohci driver (modprobe config) [ DISABLED ] [+] NFS ------------------------------------ - Check running NFS daemon [ NOT FOUND ] [+] Name services ------------------------------------ - Checking search domains [ FOUND ] - Checking /etc/resolv.conf options [ FOUND ] - Searching DNS domain name [ UNKNOWN ] - Checking /etc/hosts - Duplicate entries in hosts file [ NONE ] - Presence of configured hostname in /etc/hosts [ NOT FOUND ] - Hostname mapped to localhost [ NOT FOUND ] - Localhost mapping to IP address [ OK ] [+] Ports and packages ------------------------------------ - Searching package managers - Searching dpkg package manager [ FOUND ] - Querying package manager - Query unpurged packages [ NONE ] - Checking security repository in sources.list file or directory [ WARNING ] - Checking APT package database [ OK ] - Checking vulnerable packages [ WARNING ] - Checking upgradeable packages [ SKIPPED ] - Checking package audit tool [ INSTALLED ] Found: apt-get - Toolkit for automatic upgrades (unattended-upgrade) [ FOUND ] [+] Networking ------------------------------------ - Checking IPv6 configuration [ ENABLED ] Configuration method [ AUTO ] IPv6 only [ NO ] - Checking configured nameservers - Testing nameservers Nameserver: 127.0.0.53 [ OK ] - DNSSEC supported (systemd-resolved) [ UNKNOWN ] - Checking default gateway [ DONE ] - Getting listening ports (TCP/UDP) [ DONE ] - Checking promiscuous interfaces [ OK ] - Checking waiting connections [ OK ] - Checking status DHCP client [ NOT ACTIVE ] - Checking for ARP monitoring software [ NOT FOUND ] - Uncommon network protocols [ 0 ] [+] Printers and Spools ------------------------------------ - Checking cups daemon [ NOT FOUND ] - Checking lp daemon [ NOT RUNNING ] [+] Software: e-mail and messaging ------------------------------------ [+] Software: firewalls ------------------------------------ - Checking iptables kernel module [ FOUND ] - Checking iptables policies of chains [ FOUND ] - Chain INPUT (table: filter, target: DROP) [ DROP ] - Chain INPUT (table: security, target: ACCEPT) [ ACCEPT ] - Checking for empty ruleset [ OK ] - Checking for unused rules [ FOUND ] - Checking host based firewall [ ACTIVE ] [+] Software: webserver ------------------------------------ - Checking Apache [ NOT FOUND ] - Checking nginx [ NOT FOUND ] [+] SSH Support ------------------------------------ - Checking running SSH daemon [ FOUND ] - Searching SSH configuration [ FOUND ] - OpenSSH option: AllowTcpForwarding [ SUGGESTION ] - OpenSSH option: ClientAliveCountMax [ SUGGESTION ] - OpenSSH option: ClientAliveInterval [ OK ] - OpenSSH option: FingerprintHash [ OK ] - OpenSSH option: GatewayPorts [ OK ] - OpenSSH option: IgnoreRhosts [ OK ] - OpenSSH option: LoginGraceTime [ OK ] - OpenSSH option: LogLevel [ SUGGESTION ] - OpenSSH option: MaxAuthTries [ SUGGESTION ] - OpenSSH option: MaxSessions [ SUGGESTION ] - OpenSSH option: PermitRootLogin [ OK ] - OpenSSH option: PermitUserEnvironment [ OK ] - OpenSSH option: PermitTunnel [ OK ] - OpenSSH option: Port [ SUGGESTION ] - OpenSSH option: PrintLastLog [ OK ] - OpenSSH option: StrictModes [ OK ] - OpenSSH option: TCPKeepAlive [ SUGGESTION ] - OpenSSH option: UseDNS [ OK ] - OpenSSH option: X11Forwarding [ SUGGESTION ] - OpenSSH option: AllowAgentForwarding [ SUGGESTION ] - OpenSSH option: AllowUsers [ NOT FOUND ] - OpenSSH option: AllowGroups [ NOT FOUND ] [+] SNMP Support ------------------------------------ - Checking running SNMP daemon [ NOT FOUND ] [+] Databases ------------------------------------ No database engines found [+] LDAP Services ------------------------------------ - Checking OpenLDAP instance [ NOT FOUND ] [+] PHP ------------------------------------ - Checking PHP [ NOT FOUND ] [+] Squid Support ------------------------------------ - Checking running Squid daemon [ NOT FOUND ] [+] Logging and files ------------------------------------ - Checking for a running log daemon [ OK ] - Checking Syslog-NG status [ NOT FOUND ] - Checking systemd journal status [ FOUND ] - Checking Metalog status [ NOT FOUND ] - Checking RSyslog status [ FOUND ] - Checking RFC 3195 daemon status [ NOT FOUND ] - Checking minilogd instances [ NOT FOUND ] - Checking wazuh-agent daemon status [ NOT FOUND ] - Checking logrotate presence [ OK ] - Checking remote logging [ NOT ENABLED ] - Checking log directories (static list) [ DONE ] - Checking open log files [ DONE ] - Checking deleted files in use [ DONE ] [+] Insecure services ------------------------------------ - Installed inetd package [ NOT FOUND ] - Installed xinetd package [ OK ] - xinetd status [ NOT ACTIVE ] - Installed rsh client package [ OK ] - Installed rsh server package [ OK ] - Installed telnet client package [ OK ] - Installed telnet server package [ NOT FOUND ] - Checking NIS client installation [ OK ] - Checking NIS server installation [ OK ] - Checking TFTP client installation [ OK ] - Checking TFTP server installation [ OK ] [+] Banners and identification ------------------------------------ - /etc/issue [ FOUND ] - /etc/issue contents [ WEAK ] - /etc/issue.net [ FOUND ] - /etc/issue.net contents [ WEAK ] [+] Scheduled tasks ------------------------------------ - Checking crontab and cronjob files [ DONE ] - Checking atd status [ RUNNING ] - Checking at users [ DONE ] - Checking at jobs [ NONE ] [+] Accounting ------------------------------------ - Checking accounting information [ NOT FOUND ] - Checking sysstat accounting data [ DISABLED ] - Checking auditd [ NOT FOUND ] [+] Time and Synchronization ------------------------------------ - NTP daemon found: systemd (timesyncd) [ FOUND ] - Checking for a running NTP daemon or client [ OK ] - Last time synchronization [ 14s ] [+] Cryptography ------------------------------------ - Checking for expired SSL certificates [0/123] [ NONE ] - Found 0 encrypted and 0 unencrypted swap devices in use. [ OK ] - Kernel entropy is sufficient [ YES ] - HW RNG & rngd [ NO ] - SW prng [ NO ] - MOR variable not found [ WEAK ] [+] Virtualization ------------------------------------ [+] Containers ------------------------------------ [+] Security frameworks ------------------------------------ - Checking presence AppArmor [ FOUND ] - Checking AppArmor status [ ENABLED ] Found 36 unconfined processes - Checking presence SELinux [ NOT FOUND ] - Checking presence TOMOYO Linux [ NOT FOUND ] - Checking presence grsecurity [ NOT FOUND ] - Checking for implemented MAC framework [ OK ] [+] Software: file integrity ------------------------------------ - Checking file integrity tools - dm-integrity (status) [ DISABLED ] - dm-verity (status) [ DISABLED ] - Checking presence integrity tool [ NOT FOUND ] [+] Software: System tooling ------------------------------------ - Checking automation tooling - Automation tooling [ NOT FOUND ] - Checking for IDS/IPS tooling [ NONE ] [+] Software: Malware ------------------------------------ - Malware software components [ NOT FOUND ] [+] File Permissions ------------------------------------ - Starting file permissions check File: /boot/grub/grub.cfg [ OK ] File: /etc/at.deny [ SUGGESTION ] File: /etc/crontab [ SUGGESTION ] File: /etc/group [ OK ] File: /etc/group- [ OK ] File: /etc/hosts.allow [ OK ] File: /etc/hosts.deny [ OK ] File: /etc/issue [ OK ] File: /etc/issue.net [ OK ] File: /etc/passwd [ OK ] File: /etc/passwd- [ OK ] File: /etc/ssh/sshd_config [ SUGGESTION ] Directory: /root/.ssh [ OK ] Directory: /etc/cron.d [ SUGGESTION ] Directory: /etc/cron.daily [ SUGGESTION ] Directory: /etc/cron.hourly [ SUGGESTION ] Directory: /etc/cron.weekly [ SUGGESTION ] Directory: /etc/cron.monthly [ SUGGESTION ] [+] Home directories ------------------------------------ - Permissions of home directories [ OK ] - Ownership of home directories [ OK ] - Checking shell history files [ OK ] [+] Kernel Hardening ------------------------------------ - Comparing sysctl key pairs with scan profile - dev.tty.ldisc_autoload (exp: 0) [ DIFFERENT ] - fs.protected_fifos (exp: 2) [ DIFFERENT ] - fs.protected_hardlinks (exp: 1) [ OK ] - fs.protected_regular (exp: 2) [ OK ] - fs.protected_symlinks (exp: 1) [ OK ] - fs.suid_dumpable (exp: 0) [ DIFFERENT ] - kernel.core_uses_pid (exp: 1) [ DIFFERENT ] - kernel.ctrl-alt-del (exp: 0) [ OK ] - kernel.dmesg_restrict (exp: 1) [ OK ] - kernel.kptr_restrict (exp: 2) [ DIFFERENT ] - kernel.modules_disabled (exp: 1) [ DIFFERENT ] - kernel.perf_event_paranoid (exp: 2 3 4) [ OK ] - kernel.randomize_va_space (exp: 2) [ OK ] - kernel.sysrq (exp: 0) [ DIFFERENT ] - kernel.unprivileged_bpf_disabled (exp: 1) [ DIFFERENT ] - kernel.yama.ptrace_scope (exp: 1 2 3) [ OK ] - net.core.bpf_jit_harden (exp: 2) [ DIFFERENT ] - net.ipv4.conf.all.accept_redirects (exp: 0) [ OK ] - net.ipv4.conf.all.accept_source_route (exp: 0) [ OK ] - net.ipv4.conf.all.bootp_relay (exp: 0) [ OK ] - net.ipv4.conf.all.forwarding (exp: 0) [ OK ] - net.ipv4.conf.all.log_martians (exp: 1) [ DIFFERENT ] - net.ipv4.conf.all.mc_forwarding (exp: 0) [ OK ] - net.ipv4.conf.all.proxy_arp (exp: 0) [ OK ] - net.ipv4.conf.all.rp_filter (exp: 1) [ DIFFERENT ] - net.ipv4.conf.all.send_redirects (exp: 0) [ DIFFERENT ] - net.ipv4.conf.default.accept_redirects (exp: 0) [ OK ] - net.ipv4.conf.default.accept_source_route (exp: 0) [ DIFFERENT ] - net.ipv4.conf.default.log_martians (exp: 1) [ DIFFERENT ] - net.ipv4.icmp_echo_ignore_broadcasts (exp: 1) [ OK ] - net.ipv4.icmp_ignore_bogus_error_responses (exp: 1) [ OK ] - net.ipv4.tcp_syncookies (exp: 1) [ OK ] - net.ipv4.tcp_timestamps (exp: 0 1) [ OK ] - net.ipv6.conf.all.accept_redirects (exp: 0) [ OK ] - net.ipv6.conf.all.accept_source_route (exp: 0) [ OK ] - net.ipv6.conf.default.accept_redirects (exp: 0) [ OK ] - net.ipv6.conf.default.accept_source_route (exp: 0) [ OK ] [+] Hardening ------------------------------------ - Installed compiler(s) [ NOT FOUND ] - Installed malware scanner [ NOT FOUND ] - Non-native binary formats [ FOUND ] [+] Custom tests ------------------------------------ - Running custom tests...  [ NONE ] [+] Plugins (phase 2) ------------------------------------ ================================================================================ -[ Lynis 3.1.7 Results ]- Great, no warnings No suggestions ================================================================================ Lynis security scan details: Scan mode: Normal [▆] Forensics [ ] Integration [ ] Pentest [ ] Lynis modules: - Compliance status [?] - Security audit [V] - Vulnerability scan [V] Details: Hardening index : 61 [############ ] Tests performed : 257 Plugins enabled : 0 Software components: - Firewall [V] - Intrusion software [X] - Malware scanner [X] Files: - Test and debug information : /dev/null - Report data : /tmp/shb-audit/report.dat ================================================================================ Lynis 3.1.7 Auditing, system hardening, and compliance for UNIX-based systems (Linux, macOS, BSD, and others) 2007-2025, CISOfy - https://cisofy.com/lynis/ Enterprise support available (compliance, plugins, interface and tools) ================================================================================ [TIP]: Enhance Lynis audits by adding your settings to custom.prf (see /tmp/shb-audit/lynis/default.prf for all settings) ------------------------------------------------------------------------------ nmap: its full screen before the first step ------------------------------------------------------------------------------ Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-11-18 12:09 UTC Nmap scan report for 203.0.113.10 Host is up, received user-set (0.035s latency). Not shown: 998 closed tcp ports (conn-refused) PORT STATE SERVICE REASON 22/tcp open ssh syn-ack 80/tcp open http syn-ack Nmap done: 1 IP address (1 host up) scanned in 0.52 seconds ------------------------------------------------------------------------------ nmap: its full screen after the last step ------------------------------------------------------------------------------ Starting Nmap 7.94SVN ( https://nmap.org ) at 2026-11-18 12:15 UTC Nmap scan report for 203.0.113.10 Host is up, received user-set (0.035s latency). Not shown: 998 filtered tcp ports (no-response) PORT STATE SERVICE REASON 22/tcp open ssh syn-ack 80/tcp open http syn-ack Nmap done: 1 IP address (1 host up) scanned in 4.60 seconds ------------------------------------------------------------------------------ The check's source (scripts/live/checks/ufw-firewall-ubuntu.mjs) As it ran. ------------------------------------------------------------------------------ /** * KB: Set up a UFW firewall on Ubuntu 26.04 and 24.04 (without locking yourself out). Run per release. * * Proof standard v2 (2026-11-18): runs on the RENTED server (LIVE_VPS, a fresh stock image per release), so "from * outside" is the server's real public address: the probes come from the laptop over the internet, and the runner's * nmap scan comes from a second server (meta.audits 'nmap', before the first step and after the last), plus Lynis. * On the local VM (LIVE_VPS unset) the probes use the forwarded ports as before. * * The server is a fresh VM box (real kernel, real netfilter) reached as the sudo user `deploy`. "From outside" means * the laptop: the VM's port 80 is forwarded to 127.0.0.1:PROBE_PORT and its SSH to 127.0.0.1:2297, so every probe is a * real packet arriving on the server's network card, which ufw drops or lets through. The probes are not shown on the * page (through qemu's user network the laptop's own error text differs from what a reader's computer prints); what * the page shows is what the SERVER printed and logged. * * "Your open terminal" is an SSH ControlMaster connection opened before the firewall changes: commands sent over it * travel on that one established TCP connection, exactly like typing in a terminal you already have open, while every * other runner command is a NEW login. That is how the check proves both "the open session survives" and "a new login * is refused". Every claim below is one the article makes. */ import { spawnSync } from 'node:child_process' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' import { fileURLToPath } from 'node:url' import { SCANNER, VPS, VPS_ADDRESS, onScanner, rebootBox, redact, screen, sshOpts } from '../box.mjs' import { PROBE_PORT } from '../box/vm.mjs' import { bareBox, reportBox } from '../lib.mjs' export const meta = { audits: ['lynis', 'nmap'], // The reader's check-your-server script (plan05 phase 3): proved by the runner on the stock server and after the steps. reader: [ { item: "ufw is active", cmd: "sudo ufw status", expect: "^Status: active$", step: "step-3-enable" }, { item: "SSH is allowed", cmd: "sudo ufw status", expect: "OpenSSH\\s+(ALLOW|LIMIT)", step: "step-1-allow-ssh" }, { item: "ufw starts at boot", cmd: "systemctl is-enabled ufw", expect: "^enabled$", step: "step-3-enable" }, ], } const RELEASE = process.env.LIVE_BOX_RELEASE || '24.04' /** Where the reader's computer reaches the server: its public address on the rented server, the forwards on the VM. */ const HOST = VPS ? VPS_ADDRESS : '127.0.0.1' const WEB = VPS ? `http://${VPS_ADDRESS}/` : `http://127.0.0.1:${PROBE_PORT}/` const here = dirname(fileURLToPath(import.meta.url)) const sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms) const sh = (cmd, args, opts = {}) => spawnSync(cmd, args, { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, ...opts }) /** An HTTP request to the server's port 80 from outside. true = it answered. */ const web = () => sh('curl', ['-s', '-o', '/dev/null', '-m', '6', '-w', '%{http_code}', WEB]).stdout === '200' /** A NEW ssh login from outside (no ControlMaster). true = it got in. */ const newLogin = () => sh('ssh', ['-o', 'BatchMode=yes', '-o', 'ConnectTimeout=6', '-o', 'ControlPath=none', ...sshOpts(), `deploy@${HOST}`, 'true'], { timeout: 20000 }).status === 0 /** * The rate-limit test needs ONE source address: the laptop's traffic leaves through a VPN that may change its exit * address per connection, so on the rented server the tries come from the outside scanner (a fixed address). Its * ssh has no key: reaching sshd shows as "Permission denied (publickey)", a dropped try as a timeout. */ const reachesSshd = () => { if (!(VPS && SCANNER)) return newLogin() const r = onScanner(`ssh -o BatchMode=yes -o ConnectTimeout=6 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null nobody@${VPS_ADDRESS} true 2>&1 | tail -n 1`, 30000) return /Permission denied/.test(r.out) } /** The reader's already-open terminal: one SSH connection kept open, every command multiplexed over it. */ function openTerminal(ctx) { const sock = join(mkdtempSync(join(tmpdir(), 'shb-ufw-')), 'master') const opts = [...sshOpts(), '-o', `ControlPath=${sock}`] const up = sh('ssh', ['-o', 'BatchMode=yes', '-o', 'ControlMaster=yes', '-o', 'ControlPersist=yes', '-fN', ...opts, `deploy@${HOST}`], { timeout: 30000 }) const clean = (raw) => redact(screen(raw)).replace(/\s+$/, '') const parse = (raw) => { const m = raw.match(/\n?__exit=(\d+)$/) return { out: (m ? raw.slice(0, m.index) : raw).replace(/\s+$/, ''), exit: m ? Number(m[1]) : -1 } } const line = (cmd) => { const b64 = Buffer.from(`${cmd}; echo "__exit=$?"`).toString('base64') return ['ssh', '-tt', ...opts, `deploy@${HOST}`, `'bash -lc "$(echo ${b64} | base64 -d)"'`].join(' ') } const run = (cmd, { id } = {}) => { const r = parse(clean(sh('bash', ['-c', line(cmd)], { timeout: 120000 }).stdout ?? '')) ctx.capture(cmd, r.out, { id }) return r } const ask = (cmd, answers, { id } = {}) => { const p = sh('python3', ['-I', join(here, '..', 'box', 'pty-run.py'), line(cmd), JSON.stringify(answers), '90'], { timeout: 150000 }) const r = parse(clean(p.stdout ?? '')) ctx.capture(cmd, r.out, { id }) return r } const close = () => sh('ssh', [...opts, '-O', 'exit', `deploy@${HOST}`]) return { ok: up.status === 0, err: `${up.stderr ?? ''}`, run, ask, close } } const check = (ctx) => bareBox(ctx, async ({ sudoUser }) => { const { run, ask, L } = sudoUser() // a test web server on port 80 (the reader's would be nginx or Apache), so "port 80 open/closed" is observable L(`sudo -n sh -c 'nohup python3 -m http.server 80 --directory /tmp >/dev/null 2>&1 &' ; sleep 1`) ctx.check('(setup) the test web server on port 80 answers from outside before any firewall', web(), '') // ── before you start ───────────────────────────────────────────────────────────────────── const st = run('sudo ufw status', { id: 'status-start' }) ctx.check('ufw is installed on a fresh server but inactive', /^Status: inactive$/m.test(st.out), st.out) const port = run(`sudo ss -tlnp | grep ':22 '`, { id: 'ssh-port' }) ctx.check('SSH listens on port 22 (the port the OpenSSH profile opens)', /0\.0\.0\.0:22\b/.test(port.out) && /sshd/.test(port.out), port.out) const defs = run(`grep '^DEFAULT_.*POLICY' /etc/default/ufw`, { id: 'defaults' }) ctx.check('the defaults are already deny incoming (DROP), allow outgoing (ACCEPT)', /DEFAULT_INPUT_POLICY="DROP"/.test(defs.out) && /DEFAULT_OUTPUT_POLICY="ACCEPT"/.test(defs.out), defs.out) // ── step 1: allow SSH ──────────────────────────────────────────────────────────────────── const apps = run('sudo ufw app list', { id: 'app-list' }) ctx.check('ufw app list shows the OpenSSH profile', /^\s+OpenSSH$/m.test(apps.out), apps.out) const info = run('sudo ufw app info OpenSSH', { id: 'app-info' }) ctx.check('the OpenSSH profile opens 22/tcp', /22\/tcp/.test(info.out), info.out) const allowSsh = run('sudo ufw allow OpenSSH', { id: 'allow-ssh' }) ctx.check('ufw allow OpenSSH adds the rule for IPv4 and IPv6 while ufw is still off', /^Rules updated$/m.test(allowSsh.out) && /^Rules updated \(v6\)$/m.test(allowSsh.out), allowSsh.out) const added = run('sudo ufw show added', { id: 'show-added' }) ctx.check('ufw show added lists the saved rule before the firewall is on', /ufw allow OpenSSH/.test(added.out), added.out) // ── step 2: enable, with a terminal already open ───────────────────────────────────────── const term = openTerminal(ctx) if (!ctx.check('(setup) the reader’s open terminal (one kept SSH connection) opens', term.ok, term.err)) return try { const en = ask('sudo ufw enable', [['Proceed with operation \\(y\\|n\\)\\?', 'y']], { id: 'enable' }) ctx.check('ufw enable warns "Command may disrupt existing ssh connections" and asks y/n', /Command may disrupt existing ssh connections\. Proceed with operation \(y\|n\)\?/.test(en.out), en.out) ctx.check('after y: "Firewall is active and enabled on system startup"', /Firewall is active and enabled on system startup/.test(en.out), en.out) ctx.check('the open terminal still works after enable', term.run('echo still here', { id: 'open-after-enable' }).out.endsWith('still here'), '') ctx.check('a NEW SSH login from outside still gets in (step 4’s second terminal)', newLogin(), '') const verbose = run('sudo ufw status verbose', { id: 'status-verbose' }) ctx.check('status verbose: active, deny incoming, allow outgoing, OpenSSH allowed for v4 and v6', /^Status: active$/m.test(verbose.out) && /Default: deny \(incoming\), allow \(outgoing\), disabled \(routed\)/.test(verbose.out) && /22\/tcp \(OpenSSH\)\s+ALLOW IN\s+Anywhere/.test(verbose.out) && /\(v6\)/.test(verbose.out), verbose.out) ctx.check('logging is on (low) by default', /^Logging: on \(low\)$/m.test(verbose.out), verbose.out) // ── a port you did not allow is closed, and ufw logs it ──────────────────────────────── ctx.check('port 80 no longer answers from outside: the web server is still running but ufw drops the packets', !web(), '') const listen = L(`sudo ss -tln | grep -c ':80 '`) ctx.check('(the test web server is still listening on port 80)', /^[1-9]/.test(listen.split('\n').pop()), listen) const blk = run(`sudo grep 'DPT=80 ' /var/log/ufw.log | tail -n 1`, { id: 'blocked-log' }) ctx.check('/var/log/ufw.log records the drop: [UFW BLOCK] … DPT=80 … SYN', /\[UFW BLOCK\].*PROTO=TCP.*DPT=80 .*SYN/.test(blk.out), blk.out) // ── step 3: open the web ports ──────────────────────────────────────────────────────── const a80 = run('sudo ufw allow 80/tcp', { id: 'allow-80' }) ctx.check('ufw allow 80/tcp: "Rule added" and "Rule added (v6)"', /^Rule added$/m.test(a80.out) && /^Rule added \(v6\)$/m.test(a80.out), a80.out) const a443 = run('sudo ufw allow 443/tcp', { id: 'allow-443' }) ctx.check('ufw allow 443/tcp adds both rules', /^Rule added$/m.test(a443.out), a443.out) ctx.check('port 80 answers from outside again at once, no reload needed', web(), '') const again = run('sudo ufw allow 80/tcp', { id: 'allow-80-again' }) ctx.check('adding the same rule twice is harmless: "Skipping adding existing rule"', /Skipping adding existing rule/.test(again.out), again.out) // ── deleting rules ───────────────────────────────────────────────────────────────────── const num = run('sudo ufw status numbered', { id: 'numbered' }) ctx.check('status numbered lists IPv4 and IPv6 rules as separate numbers', /\[ 1\] OpenSSH/.test(num.out) && /443\/tcp \(v6\)/.test(num.out), num.out) const delByRule = run('sudo ufw delete allow 443/tcp', { id: 'delete-rule' }) ctx.check('ufw delete allow 443/tcp removes the IPv4 AND the IPv6 rule', /^Rule deleted$/m.test(delByRule.out) && /^Rule deleted \(v6\)$/m.test(delByRule.out), delByRule.out) const n2 = run('sudo ufw status numbered', { id: 'numbered-2' }) const v4num = (n2.out.match(/\[\s*(\d+)\] 80\/tcp\s+ALLOW IN\s+Anywhere\s*$/m) ?? [])[1] ctx.check('(found the number of the IPv4 80/tcp rule)', Boolean(v4num), n2.out) const delNum = ask(`sudo ufw delete ${v4num}`, [['Proceed with operation \\(y\\|n\\)\\?', 'y']], { id: 'delete-number' }) ctx.check('ufw delete asks first, then deletes ONE rule', /Deleting:\s*\n?\s*allow 80\/tcp/.test(delNum.out) && /^Rule deleted$/m.test(delNum.out), delNum.out) const n3 = run('sudo ufw status numbered', { id: 'numbered-3' }) ctx.check('…the IPv6 80/tcp rule is still there, and the numbers below it moved up', /80\/tcp \(v6\)\s+ALLOW IN/.test(n3.out) && !/80\/tcp\s+ALLOW IN\s+Anywhere\s*$/m.test(n3.out), n3.out) const rest = run('sudo ufw delete allow 80/tcp', { id: 'delete-80-rest' }) ctx.check('deleting by rule text then removes the IPv6 leftover ("Could not delete non-existent rule" for the IPv4 one)', /Could not delete non-existent rule/.test(rest.out) && /^Rule deleted \(v6\)$/m.test(rest.out), rest.out) L('sudo ufw allow 80/tcp >/dev/null') // back on for the rest of the run // ── rate-limit SSH ───────────────────────────────────────────────────────────────────── const lim = run('sudo ufw limit OpenSSH', { id: 'limit' }) ctx.check('ufw limit OpenSSH turns the allow rule into a limit rule: "Rule updated"', /^Rule updated$/m.test(lim.out) && /^Rule updated \(v6\)$/m.test(lim.out), lim.out) // from here every NEW login counts; the checks below go through the open terminal (no new connection) const rule = term.run(`sudo iptables -S ufw-user-input | grep -- '--dport 22'`, { id: 'limit-rule' }) ctx.check('the limit rule is the kernel "recent" match: 6 new connections in 30 seconds from one address', /--update --seconds 30 --hitcount 6/.test(rule.out) && /--set/.test(rule.out), rule.out) sleep(31000) // the logins made before the limit rule are out of the 30-second window const tries = [] for (let i = 0; i < 7; i++) tries.push(reachesSshd()) ctx.check('with the limit on, 5 new SSH connections in a row from one address reach the server and the 6th and 7th are dropped', tries.slice(0, 5).every(Boolean) && !tries[5] && !tries[6], tries.join(' ')) const lb = term.run(`sudo grep -c 'UFW LIMIT BLOCK' /var/log/ufw.log`, { id: 'limit-log' }) ctx.check('the refused logins are logged as [UFW LIMIT BLOCK]', Number(lb.out.split('\n').pop()) > 0, lb.out) sleep(10000) ctx.check('10 seconds later, while the address keeps trying, it is still refused', !reachesSshd(), '') const unlim = term.run('sudo ufw allow OpenSSH', { id: 'unlimit' }) ctx.check('ufw allow OpenSSH turns the limit back into a plain allow: "Rule updated"', /^Rule updated$/m.test(unlim.out), unlim.out) ctx.check('a new login gets in at once after that', newLogin() && reachesSshd(), '') } finally { term.close() } // ── it survives a reboot ───────────────────────────────────────────────────────────────── const secs = rebootBox() ctx.check('the server reboots and answers over SSH again (port 22 allowed)', typeof secs === 'number', String(secs)) const after = run('sudo ufw status', { id: 'after-reboot' }) // the test web server is a plain process, not a service: start it again after the reboot L(`sudo -n sh -c 'nohup python3 -m http.server 80 --directory /tmp >/dev/null 2>&1 &' ; sleep 1`) ctx.check('port 80 answers from outside after the reboot (its rule was kept)', web(), '') ctx.check('after a reboot ufw is active with the same rules', /^Status: active$/m.test(after.out) && /OpenSSH\s+ALLOW/.test(after.out) && /80\/tcp\s+ALLOW/.test(after.out), after.out, { reader: { cmd: 'sudo ufw status', expect: '^Status: active$' }, }) const ssh22 = L('sudo ufw status') ctx.check('(SSH is allowed in the firewall at the end of the steps)', /OpenSSH\s+ALLOW/.test(ssh22), ssh22, { reader: { cmd: 'sudo ufw status', expect: 'OpenSSH\\s+ALLOW' }, }) const enabledBoot = L('systemctl is-enabled ufw') ctx.check('(ufw starts at boot)', enabledBoot === 'enabled', enabledBoot, { reader: { cmd: 'systemctl is-enabled ufw', expect: '^enabled$' } }) ctx.stepsDone() // the article's steps end here (firewall on, SSH + 80 allowed, after a reboot); the undo and the mistake follow // why an open session survives enable: ufw's own before.rules accepts established connections first const est = run(`sudo grep -n 'ctstate RELATED,ESTABLISHED -j ACCEPT' /etc/ufw/before.rules | head -n 1`, { id: 'established' }) ctx.check('/etc/ufw/before.rules accepts RELATED,ESTABLISHED traffic before any user rule', /ufw-before-input -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT/.test(est.out), est.out) reportBox(ctx, L, `A fresh Ubuntu ${RELEASE} server as a provider hands it over (a rented cloud server with a public address), reached over SSH as a sudo user; the probes come from another computer on the internet.`, ['ufw', 'iptables', 'openssh-server', 'linux-image-virtual']) // ── undo: reset ────────────────────────────────────────────────────────────────────────── const reset = ask('sudo ufw reset', [['Proceed with operation \\(y\\|n\\)\\?', 'y']], { id: 'reset' }) ctx.check('ufw reset asks, backs up the rule files with a date, and leaves ufw inactive', /Resetting all rules to installed defaults/.test(reset.out) && /Backing up 'user\.rules' to '\/etc\/ufw\/user\.rules\.\d{8}_\d{6}'/.test(reset.out), reset.out) const st2 = run('sudo ufw status', { id: 'status-after-reset' }) ctx.check('after reset: Status: inactive and no rules', /^Status: inactive$/m.test(st2.out), st2.out) // ── if you enabled ufw BEFORE allowing SSH ─────────────────────────────────────────────── const t2 = openTerminal(ctx) if (!ctx.check('(setup) a terminal is open before the mistake', t2.ok, t2.err)) return try { const bad = t2.ask('sudo ufw enable', [['Proceed with operation \\(y\\|n\\)\\?', 'y']], { id: 'enable-no-ssh' }) ctx.check('ufw enable with no SSH rule still succeeds (the warning is the only guard)', /Firewall is active and enabled on system startup/.test(bad.out), bad.out) ctx.check('a NEW SSH login is now refused', !newLogin(), '') ctx.check('the terminal that was already open keeps working', t2.run('echo still here', { id: 'open-after-mistake' }).out.endsWith('still here'), '') const fix = t2.run('sudo ufw allow OpenSSH', { id: 'fix-from-open' }) ctx.check('from that open terminal, ufw allow OpenSSH adds the rule to the running firewall: "Rule added"', /^Rule added$/m.test(fix.out), fix.out) sleep(2000) ctx.check('new logins work again', newLogin(), '') } finally { t2.close() } // ── undo: turn it off ──────────────────────────────────────────────────────────────────── const dis = run('sudo ufw disable', { id: 'disable' }) ctx.check('ufw disable: "Firewall stopped and disabled on system startup"', /Firewall stopped and disabled on system startup/.test(dis.out), dis.out) ctx.check('port 80 answers again with the firewall off', web(), '') }) export default check