Skip to content

About

Unattended installation of Debian 13 without cloud-init or Terraform. Uses Debian "Preseed" functionality and secure-by-default baseline for further configuration by SSH.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Debian Preceder

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.

Try it out

  1. clone this repo
  2. copy your $SSH_PUBLIC_KEY.pub to .config/ssh
  3. sudo ./scripts/build.sh
  4. boot the generated Debian 13 ISO in a VM
  5. watch it take over the entire machine and reboot
  6. ssh ansible@$HOST -i $SSH_PRIVATE_KEY to access remotely

Assumptions and Requirements

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 uses cpio to 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:

  • xorriso
  • curl
  • gnupg

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.

Intended Installed State

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:

  1. password login is disabled for root and for the default user
  2. SSH login is disabled for root
  3. root may only be accessed via sudo or persistently through sudo su
  4. "netinst" is the smallest ISO available; all packages upgraded during install
  5. only sudo, python3, and openssh-server are added to allow for remote management.
  6. The SHA256SUMS file is signature-verified with gpgv using Debian's signing key; the checksum, signature, and key are cached in CACHE_DIR after download over TLS.
  7. 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.cfg which contains all the answers needed for automatic installation
  • debian.env which supplies the DEBIAN_USER variable.
  • post_install.sh which performs the final steps of SSH key management
  • authorized_keys which contains one or more SSH public keys for the non-root user

Only authorized_keys will remain on the target system after installation.

Configuration

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.sh

Use 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 in CACHE_DIR/DEB_VERSION (default .cache).
  • INPUT_ISO - local ISO path in the versioned cache directory.
  • ISO_URL - download URL used when INPUT_ISO is missing.
  • CHECKSUM_FILE - local checksum path in the versioned cache directory, reused when readable.
  • CHECKSUM_URL - download URL used when CHECKSUM_FILE is missing.
  • SIGNATURE_FILE - local detached signature path in the versioned cache directory, reused when readable.
  • SIGNATURE_URL - download URL used when SIGNATURE_FILE is missing.
  • SIGNING_KEY_FILE - local signing key path in the versioned cache directory, reused when readable.
  • SIGNING_KEY_URL - download URL used when SIGNING_KEY_FILE is missing.
  • SKIP_SIGNING - set to true to skip signature retrieval and verification by default; the --skip-signing option does the same for one run.
  • SSH_DIR - directory holding *.pub sources and the generated authorized_keys (default config/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).

Usage

SSH Keys

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.

build.sh

sudo -E ./scripts/build.sh calls the individual scripts in the correct order.

  1. init.sh populates config/ssh/authorized_keys.
  2. check.sh performs some basic error checks and validation.
  3. fetch.sh populates CACHE_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 gpgv unless --skip-signing is used, then checks the ISO against the checksum.
  4. build.sh itself then executes its own tasks: extract the ISO, inject the payload, and rebuild for deployment.
    • clean.sh is executed before and after the build; it removes BUILD_DIR but leaves CACHE_DIR intact.

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.

The late_command

This is a custom hook that is run after the Debian installation is ending. d-i preseed/late_command performs two tasks:

  1. copies post_install.sh, authorized_keys, and debian.env from the initrd into /root of the new system
  2. Executes sh /root/post_install.sh which creates the DEBIAN_USER account's SSH directory, installs the key, and adds a passwordless sudo rule.

Script flow

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"]
Loading

About

Unattended installation of Debian 13 without cloud-init or Terraform. Uses Debian "Preseed" functionality and secure-by-default baseline for further configuration by SSH.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages