Debian Preceder is a set of scripts that will remaster a Debian 13 ISO to allow for an unattended installation on bare-metal or as a VM without requiring cloud-init or Terraform.
It precedes the officially documented pre-seeding process by modifying the initrd to allow for a completely hands-off installation.
- clone this repo
- copy your
$SSH_PUBLIC_KEY.pubto.config/ssh sudo ./scripts/build.sh- boot the generated Debian 13 ISO in a VM
- watch it take over the entire machine and reboot
ssh ansible@$HOST -i $SSH_PRIVATE_KEYto access remotely
The following assumptions are made:
- You have internet access on the builder and for the install target.
- You can run the build as root with
sudo -E; the initrd repack usescpioto create device nodes. - No UEFI support is required.
- Debian can auto-select the disk and partition layout automatically without confirmation and automatically destroy pre-existing partitions as needed.
- You have at least one SSH public key for accessing the system post-install.
If you use Debian to build the ISO you will likely only be missing the following:
xorrisocurlgnupg
Many other utilities are needed but will already be installed on most systems:
gzip cpio sha256sum find sed mktemp
Warning
Ensure that the hard drive is the first boot device otherwise you will end up in a loop of installation and reboots.
The goal is to perform the fewest operations needed to bootstrap a secure installation for remote management over SSH. Ansible is the expected configuration tool but the system is perfectly usable for manual interactive use.
Security-minded defaults:
- password login is disabled for
rootand for the default user - SSH login is disabled for
root rootmay only be accessed viasudoor persistently throughsudo su- "netinst" is the smallest ISO available; all packages upgraded during install
- only
sudo,python3, andopenssh-serverare added to allow for remote management. - The
SHA256SUMSfile is signature-verified withgpgvusing Debian's signing key; the checksum, signature, and key are cached inCACHE_DIRafter download over TLS. - No unique information is encoded into the ISO other than the name of the non-root user and the public key for SSH access.
The final payload to be added to the ISO's initrd includes:
preseed.cfgwhich contains all the answers needed for automatic installationdebian.envwhich supplies the DEBIAN_USER variable.post_install.shwhich performs the final steps of SSH key managementauthorized_keyswhich contains one or more SSH public keys for the non-root user
Only authorized_keys will remain on the target system after installation.
config/debian.env contains all the variables that can be configured (other than SSH keys).
It contains reasonable defaults for Debian managed by a generic ansible non-root user.
Edit the file to change the defaults, or prefix a run with exported values:
DEBIAN_USER=deploy BOOT_TIMEOUT=60 sudo -E ./scripts/build.shUse sudo -E rather than plain sudo so those values survive the privilege change.
Plain sudo resets the environment, so the file defaults are used instead.
DEB_VERSION- Debian release used in download URLs, artifact names, and the cache subdirectory.CACHE_DIR- base cache directory; artifacts live inCACHE_DIR/DEB_VERSION(default.cache).INPUT_ISO- local ISO path in the versioned cache directory.ISO_URL- download URL used whenINPUT_ISOis missing.CHECKSUM_FILE- local checksum path in the versioned cache directory, reused when readable.CHECKSUM_URL- download URL used whenCHECKSUM_FILEis missing.SIGNATURE_FILE- local detached signature path in the versioned cache directory, reused when readable.SIGNATURE_URL- download URL used whenSIGNATURE_FILEis missing.SIGNING_KEY_FILE- local signing key path in the versioned cache directory, reused when readable.SIGNING_KEY_URL- download URL used whenSIGNING_KEY_FILEis missing.SKIP_SIGNING- set totrueto skip signature retrieval and verification by default; the--skip-signingoption does the same for one run.SSH_DIR- directory holding*.pubsources and the generatedauthorized_keys(defaultconfig/ssh).DEBIAN_USER- user created in the installed system.PRESEED- preseed template containing the@DEBIAN_USER@placeholder.AUTHORIZED_KEYS- SSH public key embedded in the ISO.POST_INSTALL- script run inside the installed system.OUTPUT_ISO- built ISO filename.BUILD_DIR- directory used while unpacking the ISO.BOOT_TIMEOUT- isolinux timeout in seconds (default 5).
You must provide at least one SSH public key before running the build script.
Copy your keys into config/ssh/:
cp ~/.ssh/$YOUR_KEY.pub config/ssh/init.sh regenerates config/ssh/authorized_keys from every readable *.pub file in that directory on each run, so do not edit authorized_keys by hand.
If no keys are found but the authorized_keys file exists it will be used after a 30 second delay.
Keys and the authorized_keys file are ignored by default in .gitignore.
sudo -E ./scripts/build.sh calls the individual scripts in the correct order.
init.shpopulatesconfig/ssh/authorized_keys.check.shperforms some basic error checks and validation.fetch.shpopulatesCACHE_DIR, reusing the ISO, checksum, signature, and key when they are readable and downloading missing ones from their URLs.- It verifies the checksum file with
gpgvunless--skip-signingis used, then checks the ISO against the checksum.
- It verifies the checksum file with
build.shitself then executes its own tasks: extract the ISO, inject the payload, and rebuild for deployment.clean.shis executed before and after the build; it removesBUILD_DIRbut leavesCACHE_DIRintact.
Note
If the signature or key cannot be retrieved, or gpg and gpgv are missing, the script asks whether to continue without signature verification.
Warning
If a signature fails the script will abort and you should treat it as a genuine security risk until you can correctly validate the ISO and checksum.
Pass --skip-signing to scripts/fetch.sh or scripts/build.sh to skip signature retrieval and verification entirely.
This is a custom hook that is run after the Debian installation is ending.
d-i preseed/late_command performs two tasks:
- copies
post_install.sh,authorized_keys, anddebian.envfrom the initrd into/rootof the new system - Executes
sh /root/post_install.shwhich creates theDEBIAN_USERaccount's SSH directory, installs the key, and adds a passwordless sudo rule.
flowchart TD
Abort(["Abort"])
subgraph CHECK["check.sh"]
CheckEntry["Source config/debian.env and call init.sh"] --> PubQ{"readable *.pub files in SSH_DIR?"}
PubQ -->|yes| Merge["Truncate authorized_keys and append all *.pub keys"]
PubQ -->|no| Keep["Leave authorized_keys unchanged"]
Merge --> KeyQ{"AUTHORIZED_KEYS readable?"}
Keep --> KeyQ
KeyQ -->|no| Abort
KeyQ -->|yes| Valid{"Preseed, keys, user and post-install valid?"}
end
subgraph FETCH["fetch.sh"]
FetchEntry["Ensure CACHE_DIR exists"] --> SumQ{"CHECKSUM_FILE readable?"}
SumQ -->|yes| SigQ{"Skip signing?"}
SumQ -->|no| SumDL["Download SHA256SUMS into CACHE_DIR"]
SumDL --> SigQ
SigQ -->|yes| IsoQ{"INPUT_ISO readable?"}
SigQ -->|no| Sig["Reuse or download signature and key, dearmor, verify with gpgv"]
Sig --> SigResult{"Result"}
SigResult -->|good| IsoQ
SigResult -->|bad| Abort
SigResult -->|cannot run| Prompt{"Interactive terminal?"}
Prompt -->|no| Abort
Prompt -->|yes| Answer{"Continue?"}
Answer -->|n| Abort
Answer -->|y| IsoQ
IsoQ -->|yes| Hash{"ISO hash matches checksum file?"}
IsoQ -->|no| IsoDL["Download ISO into CACHE_DIR"]
IsoDL --> Hash
Hash -->|no| Abort
Hash -->|yes| Verified(["Cached artifacts verified"])
end
subgraph BUILD["build.sh"]
BuildEntry["Unpack the ISO into BUILD_DIR"] --> Embed["Render preseed and embed files in initrd"]
Embed --> Boot["Point isolinux at the auto entry and set timeout"]
Boot --> Repack["Rebuild the ISO with xorriso"]
end
Start(["sudo -E scripts/build.sh"]) --> CheckEntry
Valid -->|no| Abort
Valid -->|yes| PreClean["clean.sh removes BUILD_DIR"] --> FetchEntry
Verified --> BuildEntry
Repack --> Done(["OUTPUT_ISO"])
Done --> PostClean["clean.sh removes BUILD_DIR; CACHE_DIR survives"]