Merge bugfix/fail2ban-no-systemd into develop

This commit is contained in:
bchanot committed 2026-10-17 12:12:03 +02:00
commit 3db51f44ec
3 files changed
+40 -9

No files matched your search

+1 -1
View File
@@ -34,7 +34,7 @@ etc/profile.d/disk-usage-warning.sh login-time low-disk warning → /etc/pro
etc/tmpfiles.d/tmp.conf disk-backed /tmp cleanup rules (offer: /tmp on disk)
etc/systemd/ssh.service.d/override.conf sshd OOM-exempt drop-in (offer: SSH memory guard)
etc/default/earlyoom earlyoom args, spare sshd / kill node first (same offer)
etc/fail2ban/jail.d/local.conf sshd jail: journal backend, all-ports ban, LAN ignored (always)
etc/fail2ban/jail.d/local.conf sshd jail: journal backend, all-ports ban, LAN ignored (offer, no on WSL)
etc/apt/apt.conf.d/20auto-upgrades unattended security upgrades on (always)
etc/ssh/sshd_config.d/20-hardening.conf sshd limits that cannot lock out, sshd -t gated (always)
cloudpex/{cloudpex,install.sh,README.md} on-demand SMB mount helper → /usr/local/bin, offered [y/N]; site values
+3 -3
View File
@@ -22,7 +22,7 @@ curl -fsSL https://git.bchanot.fr/bchanot/config/raw/branch/main/remote-install.
| `etc/tmpfiles.d/tmp.conf` | Cleanup rules for a disk-backed `/tmp` (wiped at boot, 10-day purge). Deployed by the `/tmp` on disk offer. |
| `etc/systemd/ssh.service.d/override.conf` | `ssh.service` drop-in: sshd exempt from the OOM killer + memory reclaim protection. Deployed by the SSH memory guard offer. |
| `etc/default/earlyoom` | earlyoom arguments: spare sshd/systemd, kill node/java first. Deployed by the SSH memory guard offer. |
| `etc/fail2ban/jail.d/local.conf` | fail2ban sshd jail: journal backend, all-ports ban, 5 tries / 10 min / 1 h, private LAN never banned. Deployed on every Linux install. |
| `etc/fail2ban/jail.d/local.conf` | fail2ban sshd jail: journal backend, all-ports ban, 5 tries / 10 min / 1 h, private LAN never banned. Deployed when fail2ban is accepted (offered on Linux, default yes, no on WSL). |
| `etc/apt/apt.conf.d/20auto-upgrades` | Enables unattended security upgrades (what `dpkg-reconfigure` writes). Deployed on every Linux install. |
| `etc/ssh/sshd_config.d/20-hardening.conf` | sshd limits that cannot lock you out: `PermitRootLogin no`, `MaxAuthTries 3`, `LoginGraceTime 20`. Deployed on every Linux install after `sshd -t`. |
| `vim/vimrc` | Vim config: pathogen, molokai, syntastic (C with `-Wall -Werror -Wextra`), NERDTree, 42-style canonical class generators (`:ClassH`, `:ClassC`). |
@@ -75,7 +75,7 @@ What it does:
10. On Linux, installs **code-server** (VS Code in the browser) via its vendor script — skipped if already present — and enables the `code-server@<login>` systemd service (login from `id -un`: the bashrc overrides `$USER`).
11. On Linux, **offers** (`[Y/n]`, Enter = yes) to install **`ubuntu-desktop-minimal`** (GDM + GNOME Shell, ~1.5 GB): the RDP remote login below hands out a GNOME session, which a bare server install does not have. If accepted, then **offers** (`[Y/n]`) **RDP remote login** via `gnome-remote-desktop` (Wayland-native); no desktop means no RDP question. On **WSL** (`WSL_DISTRO_NAME` set or `microsoft` in `/proc/version`) both default to **no** (`[y/N]`): Windows owns the display, and the desktop drags in NetworkManager + systemd-resolved, which rewrite `/etc/resolv.conf` and break DNS for the rest of the install. With no terminal attached the default applies. The RDP setup installs the daemon + `openssl`, generates a self-signed TLS cert once, and prompts interactively for shared "gate" credentials (skipped when no terminal is attached, or already set). Disables `xrdp` if present; opens UFW port `3389` only when UFW is already active. Finally, when `lspci` sees an NVIDIA GPU, runs `ubuntu-drivers install` to put on the driver the distro recommends for the card (no version pinned; loads at the next reboot). Skipped on machines without an NVIDIA GPU.
12. On Linux, at the very end, **offers** (`[y/N]`) to install the **`cloudpex`** NAS mount helper to `/usr/local/bin` via `cloudpex/install.sh`, which prompts for the NAS host, share name, SMB user, mount point and SMB version and writes them to `/etc/cloudpex.conf` (root, `0600`; an existing config is shown and kept unless you say `n`; skipped when no terminal is attached). Nothing is mounted, no password stored, see [`cloudpex/README.md`](cloudpex/README.md).
13. On Linux, installs the **security baseline**, always, no prompt: **fail2ban** (+ `nftables`) with `etc/fail2ban/jail.d/local.conf` (sshd jail reading the journal, bans the offending IP on every port so the SSH port does not matter, 5 failures in 10 min → 1 h ban, loopback and private LAN ranges never banned); **unattended-upgrades** enabled through `etc/apt/apt.conf.d/20auto-upgrades`; and the **sshd drop-in** `etc/ssh/sshd_config.d/20-hardening.conf` (`PermitRootLogin no`, `MaxAuthTries 3`, `LoginGraceTime 20`), checked with `sshd -t` (`/run/sshd` is created first, so the check also works when sshd is not running) and removed again if sshd rejects it, then reloaded with `systemctl try-reload-or-restart ssh` when `ssh.service` is active; otherwise (WSL, sshd never started) the drop-in stays in place and applies at the next sshd start. Authentication methods, port and user lists are left as they are.
13. On Linux, installs the **security baseline**: **fail2ban** (+ `nftables`, offered: default yes, no on WSL; started only when systemd runs) with `etc/fail2ban/jail.d/local.conf` (sshd jail reading the journal, bans the offending IP on every port so the SSH port does not matter, 5 failures in 10 min → 1 h ban, loopback and private LAN ranges never banned); **unattended-upgrades** enabled through `etc/apt/apt.conf.d/20auto-upgrades`; and the **sshd drop-in** `etc/ssh/sshd_config.d/20-hardening.conf` (`PermitRootLogin no`, `MaxAuthTries 3`, `LoginGraceTime 20`), checked with `sshd -t` (`/run/sshd` is created first, so the check also works when sshd is not running) and removed again if sshd rejects it, then reloaded with `systemctl try-reload-or-restart ssh` when `ssh.service` is active; otherwise (WSL, sshd never started) the drop-in stays in place and applies at the next sshd start. Authentication methods, port and user lists are left as they are.
14. On Linux, at the very end, **offers** (`[y/N]`, skipped when no terminal is attached) to move **`/tmp` to disk**: Ubuntu mounts `/tmp` as a RAM-backed tmpfs capped at 50% of RAM, which agent runs fill, halving the RAM and breaking every shell with "No space left on device". Accepting masks `tmp.mount` and installs `etc/tmpfiles.d/tmp.conf` (wipe at boot, 10-day purge). Effective at the next reboot.
15. On Linux, at the very end, **offers** to keep **SSH reachable under memory pressure**: installs the `ssh.service` drop-in (`OOMScoreAdjust=-1000`, `MemoryMin=256M`) and `earlyoom` with `etc/default/earlyoom` (kills the largest process, `node`/`java` first and never `sshd`, once free RAM and swap both drop under 10%). Restarting `ssh` keeps open sessions. Note: `MemoryMin` protects the sshd daemon only; login sessions live in `user.slice`, so no setting can reserve RAM for a future shell. earlyoom acting in time is the real protection.
16. On Linux, at the very end, **offers** to set up **rootless Docker**: installs `uidmap dbus-user-session slirp4netns docker-ce-rootless-extras`, runs `dockerd-rootless-setuptool.sh install` as you (the apt package puts it in `/usr/bin`, so no `PATH` line is needed, unlike the `~/bin` install from `get.docker.com/rootless`), then `loginctl enable-linger` so the user daemon starts at boot. The tool creates `~/.config/systemd/user/docker.service` and switches the CLI to the `rootless` context; the deployed bashrc exports `DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock` whenever that socket exists, for tools that ignore contexts. The rootful daemon is disabled first (`systemctl disable --now docker.service docker.socket`, socket removed), as the docs recommend: `docker` then only talks to your user daemon. Needs `/etc/subuid` and `/etc/subgid` entries for the user (Ubuntu adds them at user creation).
@@ -93,7 +93,7 @@ What it does:
- **Remote access**: `gnome-remote-desktop openssl` (apt, offered after the desktop) + `code-server` (via its vendor install script, not apt) — RDP remote login + browser VS Code
- **pipx**: `PyMuPDF` (`pymupdf`), `Markdown` (`markdown_py`)
- **Rust (rustup, not apt)**: `stable` toolchain, default profile + `rust-analyzer rust-src`
- **Security baseline (Linux, always)**: `fail2ban nftables unattended-upgrades`
- **Security baseline (Linux)**: `unattended-upgrades` always; `fail2ban nftables` offered (default yes, no on WSL)
- **Optional (end-of-install offer, Linux)**: `earlyoom`; `uidmap dbus-user-session slirp4netns` (rootless Docker)
The script is re-runnable: each run re-backs up to `~/Oldconfig` (overwriting the previous backup), re-clones plugins, skips Docker if already installed, and re-deploys the `bin/` scripts.
+36 -5
View File
@@ -195,6 +195,13 @@ offer_docker_rootless() {
echo "Rootless Docker ready: CLI context 'rootless' selected; the bashrc exports DOCKER_HOST when its socket exists."
}
# True when systemd is PID 1. WSL distros without systemd=true in /wsl.conf (and
# containers) have none: apt still installs the packages, but every systemctl call
# fails and set -e would abort the install.
systemd_running() {
[ -d /run/systemd/system ]
}
# fail2ban: bans an IP on every port after repeated SSH failures. The sshd jail
# reads the journal (works with or without /var/log/auth.log) and bans all ports,
# so the port sshd listens on does not matter — the previous server's jail only
@@ -205,8 +212,12 @@ install_fail2ban() {
sudo apt-get install -y fail2ban nftables
sudo install -D -m 0644 "$SCRIPT_DIR/etc/fail2ban/jail.d/local.conf" \
/etc/fail2ban/jail.d/local.conf
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
if systemd_running; then
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
else
echo "systemd not running (WSL?) — fail2ban installed, not started. Enable systemd=true in /wsl.conf, then: sudo systemctl enable --now fail2ban" >&2
fi
}
# Automatic security updates: the file dpkg-reconfigure would write, deployed
@@ -268,6 +279,18 @@ confirm() {
esac
}
# fail2ban offer, yes by default ([Y/n]); on WSL the default flips to no: sshd is
# rarely exposed there and, without systemd, the service cannot run anyway.
offer_fail2ban() {
local default=y
is_wsl && default=n
if ! confirm "Install fail2ban (bans SSH brute-force IPs on every port)?" "$default"; then
echo "fail2ban skipped."
return 0
fi
install_fail2ban
}
# WSL (Windows Subsystem for Linux): no GDM, no GNOME session, no RDP target — the
# Windows side owns the display. Detected from the env var WSL sets, else the kernel
# string.
@@ -341,6 +364,10 @@ offer_ssh_memory_guard() {
echo "SSH memory guard already in place — skipping"
return 0
fi
if ! systemd_running; then
echo "systemd not running (WSL?) — SSH memory guard skipped" >&2
return 0
fi
confirm "Protect SSH under memory pressure (sshd OOM-exempt + earlyoom)?" || return 0
if [ "$ssh_done" = 0 ]; then
sudo install -D -m 0644 "$SCRIPT_DIR/etc/systemd/ssh.service.d/override.conf" "$dropin"
@@ -765,7 +792,11 @@ if command -v apt-get >/dev/null 2>&1; then
curl -fsSL https://code-server.dev/install.sh | sh
fi
# id -un, not $USER: the deployed bashrc sets USER to the git/vim identity.
sudo systemctl enable --now "code-server@$(id -un)"
if systemd_running; then
sudo systemctl enable --now "code-server@$(id -un)"
else
echo "systemd not running (WSL?) — code-server installed, not started" >&2
fi
# GNOME desktop + RDP remote login, both offered ([Y/n]; [y/N] on WSL).
offer_desktop
@@ -776,8 +807,8 @@ if command -v apt-get >/dev/null 2>&1; then
# Low-disk login warning (system-wide profile.d snippet).
install_disk_warning
# Security baseline: brute-force bans, automatic security updates, sshd limits.
install_fail2ban
# Security baseline: brute-force bans (offered), security updates, sshd limits.
offer_fail2ban
install_unattended_upgrades
harden_sshd
elif [ "$(uname -s)" = "Darwin" ]; then