Skip to content

Debian Setup ​

Personal Debian VPS dotfiles and setup scripts powered by apt, proto, and Oh My Zsh.

Prerequisites ​

The script requires either root or a user with sudo access. It will exit early with an error if neither is available.

PrerequisiteNotes
sudo or rootRequired to install packages and write to system directories
curlDownloads the pinned releases (proto, Helm, k9s, GCM) and apt keys
gitInstalled automatically via apt in the common step

Installation ​

Remote (fresh server) ​

sh
# Full install — all profiles, dotfiles, completions
bash <(curl -fsSL https://raw.githubusercontent.com/KevinDeBenedetti/dotfiles/v0.20.0/os/debian/init.sh) -a

The script clones the latest release of the repository to ~/.dotfiles (or checks that release out in an existing clone), then re-executes from there. Set DOTFILES_REF to run another tag or branch (DOTFILES_REF=main).

Local ​

sh
# Clone
git clone https://github.com/KevinDeBenedetti/dotfiles.git ~/.dotfiles
cd ~/.dotfiles

# Full install
./os/debian/init.sh -a

# Dotfiles only
./os/debian/init.sh -d

# Specific profiles + completions
./os/debian/init.sh -p "base,kubernetes" -c

Flags ​

FlagDescription
-aFull install: all profiles + dotfiles + completions + cleanup
-p <profiles>Comma-separated list of profiles (e.g. base,kubernetes)
-dLink dotfiles into $HOME
-cInstall zsh CLI completions
-lLite mode — skip optional/heavy packages
-u <user>Create a non-root sudo user before the security profile hardens SSH
-hPrint help

At least one flag is required. Running without flags prints help and exits.

Common Packages ​

Installed unconditionally before any profile (via apt):

ca-certificates, curl, gnupg, gzip, jq, unzip, wget, xz-utils, git, build-essential

Oh My Zsh is also installed at this stage if ~/.oh-my-zsh does not exist: it is cloned at the commit pinned in os/helpers/oh-my-zsh.sh, with no installer script, and updates itself from master afterwards.

Profiles ​

base ​

Core CLI tools installed via apt. Split into lite (always) and additional (full mode only).

Lite:

ToolDescription
Docker CEDocker engine from the official upstream repository
docker-ce, docker-ce-cli, containerd.ioCore engine, CLI client, and container runtime
docker-buildx-plugin, docker-compose-pluginBuildKit and Compose v2 plugins
ansibleAgentless configuration management and provisioning
fzfFuzzy finder for shell history, files, and more
sshOpenSSH client
treeDirectory tree visualizer
watchRepeat a command at intervals
yqPortable YAML/JSON/TOML processor
rsyncIncremental file transfer
TerraformInfrastructure as code, from HashiCorp's apt repository
Git Credential ManagerHTTPS Git credential helper behind credential.helper = manager
protoToolchain version manager (pinned release, SHA-256 verified)

Docker CE is installed from https://download.docker.com/linux/debian using the official GPG key. The calling user is automatically added to the docker group.

The apt keys of Docker, HashiCorp and Kubernetes (pkgs.k8s.io) are trusted only when they match the fingerprint pinned in the script: a rotated or swapped key aborts the run before apt trusts it. When a vendor rotates its key, update the fingerprint from the vendor's announcement.

On a node managed by the infra repository, the script leaves Docker out. It recognises such a node by the sshd drop-in that repository writes, /etc/ssh/sshd_config.d/00-infra-hardening.conf, the same marker that makes it skip SSH hardening. Those nodes run k3s with its own containerd, and their Ansible removes Docker, whose iptables rules forward published ports around the host firewall.

Git Credential Manager comes from the release pinned in os/debian/setup-base.sh (.deb, amd64 or arm64), checked against the SHA-256 pinned next to it before apt installs it. A download that fails or does not match stops the profile, as for every pinned release (proto, Helm, k9s). A machine that already has git-credential-manager or k9s keeps the build it has: bumping a pin does not upgrade it. Linux has no default credential store, so when none is configured the script sets credential.credentialStore cache in the system config (/etc/gitconfig): credentials stay in memory (15 minutes by default), never on disk.

Additional (full mode):

ToolDescription
ghGitHub CLI — PRs, issues, repos from the terminal
nmapNetwork exploration and port scanning

security ​

Hardens the system using a layered approach. Activated with -p security or included in -a (full install).

Environment variables ​

Set these before invoking the script to customize security behaviour:

VariableDefaultDescription
SSH_PORT22TCP port sshd listens on
SSH_ALLOWED_USERS(all)Space-separated list of users permitted to log in via SSH
SSH_NOPASSWDfalseGive the user created by -u passwordless sudo
COPY_ROOT_SSH_KEYtrueAdd root's authorized_keys to the user created by -u, keeping its own
HARDEN_TMPfalseRemount /tmp as a noexec tmpfs capped at 1G (opt-in)
HARDEN_IPV6_RAfalseIgnore IPv6 router advertisements (opt-in)
sh
# Example: custom port + restrict SSH to a single user
SSH_PORT=2222 SSH_ALLOWED_USERS="deploy" bash <(curl -fsSL ...) -a

SSH hardening (/etc/ssh/sshd_config.d/00-hardening.conf) ​

SettingValueEffect
Port$SSH_PORTConfigurable port (default: 22)
PermitRootLoginnoDisable direct root login (see below)
PasswordAuthenticationnoKey-only authentication
MaxAuthTries3Block brute-force attempts
X11ForwardingnoNo X11 tunnelling
AllowTcpForwardingnoNo arbitrary port forwarding
ClientAliveInterval300Disconnect after 5 min idle
AllowUsers$SSH_ALLOWED_USERSRestrict login to named users (optional)

sshd keeps the first value it reads and loads drop-ins in lexical order, so the file is named 00- to win over others such as cloud-init's 50-cloud-init.conf. After writing it, the script checks the effective configuration (sshd -T) and warns if PermitRootLogin or PasswordAuthentication is still overridden.

Two safeguards keep the hardening from locking you out:

  • Root login stays on (key only) until another admin can log in. Root login is turned off only when a non-root member of the sudo group has a non-empty ~/.ssh/authorized_keys, can run sudo (a password set, or a NOPASSWD rule) and is listed in SSH_ALLOWED_USERS when that is set. Otherwise the script writes PermitRootLogin prohibit-password and warns; when SSH_ALLOWED_USERS is set, root is added to AllowUsers for as long as that lasts, since AllowUsers refuses every user it does not name. Create the user with -u <user> (with SSH_NOPASSWD=true, or set its password with sudo passwd <user>), then re-run the security profile.
  • A drop-in that breaks sshd is moved aside. If sshd -t passed before the drop-in was written and fails after, the file is renamed to 00-hardening.conf.rejected, sshd is not restarted and the run stops (UFW is not reconfigured for a port sshd does not listen on).

UFW firewall ​

Default policy: deny all incoming, allow all outgoing. Rules added:

RuleProtocolComment
$SSH_PORT/tcpTCPSSH (respects custom port)
80/tcpTCPHTTP
443/tcpTCPHTTPS

UFW is reset only on its first run, while it is inactive: re-running the security profile adds these rules again and keeps those you added since.

The firewall is configured before sshd is hardened, so a re-run with another SSH_PORT opens the new port before sshd restarts on it. Once sshd has restarted, the rule of the previous port is removed; when the restart fails, that port stays open and a warning gives the command that closes it.

WARNING

Docker writes its own iptables rules ahead of UFW's, so UFW does not filter ports published by containers. When Docker is installed, the script sets "ip": "127.0.0.1" in /etc/docker/daemon.json: -p 5432:5432 then binds to loopback only. Publish a service on purpose with an explicit address (-p 0.0.0.0:443:443).

Fail2Ban (/etc/fail2ban/jail.local) ​

SettingValue
bantime1 hour
findtime10 minutes
maxretry3 attempts
backendsystemd
banactionufw

python3-systemd is installed with it: the systemd backend needs it, and it is only a Recommends of the fail2ban package.

On a node managed by the infra repository (same marker as for Docker, /etc/ssh/sshd_config.d/00-infra-hardening.conf), the script skips SSH hardening, UFW and Fail2Ban: sshd and the firewall belong to that repository's Ansible, and a jail whose ban action is UFW could not ban anyone where UFW is not installed. The other hardening steps still run.

Sysctl hardening (/etc/sysctl.d/99-security.conf) ​

Network:

ParameterValueEffect
net.ipv4.tcp_syncookies1SYN flood protection
net.ipv4.tcp_rfc13371TIME_WAIT assassination protection
net.ipv4.ip_forward0No IP forwarding
net.ipv4.conf.all.accept_redirects0Ignore ICMP redirects (MITM)
net.ipv4.conf.all.rp_filter1Reverse path filtering (anti-spoof)

Kernel:

ParameterValueEffect
kernel.kptr_restrict2Hide kernel pointer addresses in /proc
kernel.dmesg_restrict1Restrict kernel log access to root
kernel.randomize_va_space2Full ASLR enabled
kernel.yama.ptrace_scope1Restrict ptrace to parent processes
net.core.bpf_jit_harden2Harden BPF JIT compiler
vm.mmap_min_addr65536Prevent null pointer dereference exploits

Filesystem:

ParameterValueEffect
fs.suid_dumpable0No core dumps for setuid binaries
fs.protected_symlinks1Protect symlinks in world-writable sticky dirs
fs.protected_hardlinks1Only owner can follow hardlinks
fs.protected_fifos2Restrict FIFO creation in sticky directories
fs.protected_regular2Restrict regular file creation in sticky directories

Shared memory & /tmp (/etc/fstab) ​

Mount pointOptions
/dev/shmnoexec,nosuid,nodev
/tmpnoexec,nosuid,nodev,size=1G

The /tmp entry is only added with HARDEN_TMP=true: noexec on /tmp breaks some apt/dpkg maintainer scripts and builds, and the 1G cap is wrong for small servers.

AppArmor ​

Installs apparmor and apparmor-utils and enables the service. The GRUB boot parameters (apparmor=1 security=apparmor) are added only where the kernel does not run AppArmor already, which Debian does by default since version 10. Each profile keeps the mode its package ships it in: forcing every profile to enforce breaks the services whose profile is in complain mode on purpose.

CrowdSec (full mode only) ​

Collaborative threat-intelligence IPS. Adds CrowdSec's packagecloud apt repository directly (no remote install script runs as root): the repository key must match the fingerprint pinned in setup-security.sh, otherwise the run aborts before apt trusts it. Then installs crowdsec and adds:

  • crowdsec-firewall-bouncer-iptables — automatic firewall banning
  • Collections: crowdsecurity/linux, crowdsecurity/sshd

Unattended upgrades ​

Configures automatic security patches only, in /etc/apt/apt.conf.d/52dotfiles-unattended-upgrades: it clears the origins of the packaged 50unattended-upgrades (left untouched, it is a dpkg conffile) and allows only the security archive (label=Debian-Security, or Ubuntu's <codename>-security). Auto-reboot is disabled.

Check which upgrades it would apply with sudo unattended-upgrade --dry-run -d.

Security audit tools (full mode only) ​

ToolDescription
lynisSystem and security auditing
rkhunterRootkit scanner
chkrootkitAnother rootkit checker
auditdKernel audit framework

kubernetes ​

Tools for Kubernetes cluster management.

Lite:

ToolDescription
kubectlKubernetes command-line client, from the official pkgs.k8s.io repo of one pinned minor (install_kubectl in os/debian/setup-kubernetes.sh), moved to each new minor by Renovate; a re-run moves a kubectl from an older minor's repo

On a node managed by the infra repository (same marker as for Docker, /etc/ssh/sshd_config.d/00-infra-hardening.conf), the script installs neither kubectl nor the pkgs.k8s.io repository: k3s ships its own kubectl, and that repository's Ansible removes both on every run.

Additional (full mode):

ToolDescription
helmKubernetes package manager (pinned release, SHA-256 verified; amd64/arm64)
k9sTerminal UI for Kubernetes clusters (pinned release, SHA-256 verified)

Dotfiles Linking ​

Running -d symlinks (or copies) config files from the repository into $HOME. Any existing file is backed up with a datestamp (e.g. ~/.zshrc.bak.20260311) before being replaced.

SourceTargetMethod
config/zsh/.zshrc~/.zshrccopy¹
config/git/.gitconfig~/.gitconfigsymlink
config/git/ignore~/.config/git/ignoresymlink
config/proto/.prototools~/.proto/.prototoolssymlink
config/oh-my-zsh/*.zsh-theme~/.oh-my-zsh/custom/themes/symlink
config/shell/*~/.config/dotfiles/symlink
config/ssh/config~/.ssh/configsymlink
config/claude/settings.json~/.claude/settings.jsonsymlink
config/claude/hooks/*~/.claude/hooks/symlink
config/skills/*/~/.claude/skills/symlink
config/skills/*/~/.copilot/skills/symlink
config/skills/*/SKILL.md~/.config/opencode/commands/*.mdsymlink³
config/agents/AGENTS.md~/.claude/AGENTS.mdsymlink
config/claude/CLAUDE.md~/.claude/CLAUDE.mdsymlink
config/agents/AGENTS.md~/.config/opencode/AGENTS.mdsymlink
config/agents/AGENTS.md~/.copilot/copilot-instructions.mdsymlink
config/opencode/opencode.json~/.config/opencode/opencode.jsonsymlink
config/copilot/hooks/*~/.copilot/hooks/symlink
config/ai-tools/~/.config/ai-toolssymlink
scripts/*/* (executables)~/.local/bin/symlink
config/ollama/~/.config/ollamasymlink
config/vscode/settings.json~/.config/Code/User/settings.jsonsymlink²
config/vscode/mcp.json~/.config/Code/User/mcp.jsonsymlink²

¹ .zshrc is copied rather than symlinked so machine-specific patches can be applied without affecting the tracked file.

² Only when VS Code is installed: settings.json and mcp.json need the code CLI on PATH.

³ Only for a user-invoked skill (a slash command): see Agent Skills.

Local override stubs ​

The -d step also creates the following stub files if they do not already exist. They are never tracked by git and always take precedence:

FilePurpose
~/.zshrc.localMachine-specific zsh aliases, exports, and path additions
~/.gitconfig.localMachine-specific git overrides (e.g. user.email, signingkey)
~/.config/dotfiles/env.local.shMachine-specific environment variable overrides (no API keys)

SSH allowed signers ​

The script adds the signing key (user.signingkey, else the first ~/.ssh/id_*.pub, ed25519 first) to ~/.ssh/allowed_signers for local SSH commit signature verification, keeping any other signer in the file.

Completions ​

Running -c installs zsh completions for:

ToolSource
ghgh completion -s zsh
protoproto completions --shell zsh
uvuv generate-shell-completion zsh
zsh-completionsCloned at a pinned commit into Oh My Zsh custom plugins, added to fpath (a ~/.zshrc linked by scripts/symlink.sh is left alone: enable the line in config/zsh/.zshrc)

Completions are written to /usr/local/share/zsh/site-functions (with sudo when not root).

Zsh Configuration ​

The .zshrc at config/zsh/.zshrc is copied to ~/.zshrc so machine-specific patches can be applied without affecting the tracked file.

History ​

SettingValueEffect
HISTSIZE10000Number of commands kept in memory per session
SAVEHIST10000Number of commands persisted to ~/.zsh_history
HIST_STAMPSyyyy-mm-ddDate prefix on every history entry
HISTFILE~/.zsh_historyPersistent history file location

Theme ​

A custom Oh My Zsh theme kevin-de-benedetti is linked from config/oh-my-zsh/ into ~/.oh-my-zsh/custom/themes/ and set via ZSH_THEME.

Plugins ​

The following Oh My Zsh plugins are enabled in .zshrc:

PluginWhat it provides
aliasesals command — lists all active aliases with descriptions
colored-man-pagesANSI colour for man pages — much easier to read
direnvLoads .envrc files if direnv is installed (not by these scripts on Debian)
dockerDocker CLI completion and aliases (dbl, dcin, dps, etc.)
docker-composedocker compose completion and shorthand aliases (dcup, dcdown, etc.)
ghGitHub CLI (gh) shell completion
gitExtensive Git aliases (gst, gco, glog, gcmsg, etc.) and branch in prompt
gitignoregi <lang> — fetches a .gitignore template from gitignore.io
rsyncAliases for common rsync patterns (rsync-copy, rsync-move, etc.)
sudoDouble-press ESC to prepend sudo to the current or previous command

fzf Integration ​

fzf is installed by the base profile. The tracked .zshrc adds the fzf Oh My Zsh plugin whenever fzf is on PATH, which turns on its completion and these key bindings:

BindingAction
CTRL-TFuzzy-search files/directories and paste the path
CTRL-RFuzzy-search command history and run selected entry
ALT-CFuzzy cd into a subdirectory

Local Overrides ​

The following files are sourced at the end of .zshrc if they exist. They are never tracked by git:

FilePurpose
~/.config/dotfiles/env.local.shMachine-specific environment variables (no API keys)
~/.zshrc.localMachine-specific aliases, path additions, and exports

Shell Functions ​

Custom functions live in config/shell/functions.sh and are sourced automatically by .zshrc. Run lsfn to list all functions with their help text.

FunctionUsageDescription
b64db64d <string>Decode a base64 string
b64eb64e <string>Encode a string to base64
browserbrowser [-- <url>]Start a Browsh terminal browser via Docker
cheat_glowcheat_glow <sheet>Render a cheat cheatsheet through glow at 150 columns for readability
check_certcheck_cert <url>Print TLS certificate details for a domain using curl
dksdks <secret> [namespace]Decode a Kubernetes secret — outputs all .data values base64-decoded via yq
kbpkbp <port>Kill the process currently listening on the given TCP port
randompassrandompass [length]Generate a secure random password (default 24 chars) with mixed complexity
timestampdtimestampd <unix_ts>Convert a Unix timestamp to a human-readable date (cross-platform)
timestampetimestampe <YYYY-mm-ddTHH:MM:ss>Convert a date string to its Unix timestamp (cross-platform)
vpnvpn <up|down|status|list> [tunnel]Manage WireGuard tunnels via wg-quick (aliases: vup, vdown, vpns)

Run any function with -h or --help to see its usage message, e.g. dks -h.

Git Configuration ​

config/git/.gitconfig is symlinked to ~/.gitconfig. Key settings:

SectionSettingValueEffect
useruseConfigOnlytrueIdentity must come from a config file, never guessed
pushdefaultsimplePush to the tracking branch only (safe default)
pullrebasetrueAlways rebase on pull instead of merge
branchautosetuprebasealwaysNew branches track their remote with rebase
rerereenabledtrueRecord and replay conflict resolutions automatically
commitgpgsigntrueSign every commit with your SSH key
taggpgSigntrueSign every tag with your SSH key
gpgformatsshUse SSH key (not GPG keyring) for signing
gpg.sshallowedSignersFile~/.ssh/allowed_signersFile that maps emails to trusted public keys
initdefaultBranchmainNew repositories default to main
credentialhelpermanagerHTTPS auth through Git Credential Manager³
urlinsteadOfgit@github.com:GitHub SSH remotes are rewritten to HTTPS (GCM)

³ Git Credential Manager is installed by the base profile; without it, git warns that credential-manager is not a git command and falls back to prompting. Details in Git.

Machine-specific overrides ​

Create ~/.gitconfig.local — it is [include]d at the bottom of .gitconfig and is never tracked by git:

ini
# ~/.gitconfig.local
[user]
  email = server@yourdomain.com
  signingkey = ~/.ssh/id_ed25519_server.pub

SSH commit signing ​

The dotfiles install adds the signing key to ~/.ssh/allowed_signers: the key in user.signingkey, else the first of ~/.ssh/id_ed25519.pub, id_ecdsa.pub and id_rsa.pub. It updates that key's line only, keeping any other signer in the file. This allows Git to verify signed commits locally with git log --show-signature.

SSH Client Configuration ​

config/ssh/config is symlinked to ~/.ssh/config. The global Host * block applies to every connection:

DirectiveValueEffect
SendEnv -LC_* -LANG(off)Do not forward locale variables — avoids setlocale warnings on servers
ControlMasterautoReuse an existing connection if one is already open
ControlPath~/.ssh/cm-…Socket path for multiplexed connections
ControlPersist60sKeep the master connection open for 60 s after the last session closes
ServerAliveInterval60Send a keepalive packet every 60 s
ServerAliveCountMax3Drop the connection after 3 missed keepalives (~3 min)

proto Toolchain ​

config/proto/.prototools is symlinked to ~/.proto/.prototools. It pins global tool versions and configures proto's behaviour:

toml
# bun, node, pnpm, yarn, python and go: one exact version each
# (see the file for the numbers)
npm   = "bundled"   # ships with the Node.js version

[tools.node]
bundled-npm = true  # keep npm in sync with node

[tools.npm]
shared-globals-dir = true  # global npm packages in a single shared dir

[settings]
auto-install  = true     # install missing tool versions automatically
auto-clean    = true     # remove unused tool versions after upgrades
pin-latest    = "global" # record the resolved "latest" version globally

Managing tool versions ​

sh
# Install a specific version
proto install node 22

# Install a version and pin it in the current directory only (./.prototools)
proto install python 3.12 --pin local

# List the configured tools and whether each is installed
proto status

# Upgrade proto itself
proto upgrade

Useful apt Commands ​

sh
# Refresh package index
sudo apt-get update

# Upgrade all installed packages
sudo apt-get upgrade

# Install a package without recommended extras
sudo apt-get install -y --no-install-recommends <package>

# Search for a package
apt-cache search <keyword>

# Remove a package and its config
sudo apt-get purge <package> && sudo apt-get autoremove

Common Issues ​

sudo not available on a fresh VPS:

sh
# As root, install sudo and add your user
apt-get install -y sudo
usermod -aG sudo <username>
# Then log out and back in

Docker CE daemon not started after install:

sh
sudo systemctl enable docker
sudo systemctl start docker
# Log out and back in for group membership to take effect
# (the script already runs: usermod -aG docker $USER)

Docker GPG key or repository error:

sh
# Re-add the GPG key manually
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg \
  | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

kubectl not found after install:

sh
# Verify the apt source was added correctly
cat /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update && sudo apt-get install -y kubectl