Linux

Creating Custom APT Repositories for Internal Package Distribution on Ubuntu 24.04

Aseem Kishore
29 min read

The Back Room Tech is reader-supported. We may earn a commission when you buy through links on our site. Learn more.

A custom APT repository on Ubuntu 24.04 lets every server you configure for it install internal tools and patched packages with a plain apt install. You’ll generate a dedicated signing key, build the repo with reprepro or aptly, serve it over nginx, and set up clients the current way. That means a per-repo key in /etc/apt/keyrings/ and a deb822 .sources file with Signed-By. No apt-key involved.

Short answer: pick reprepro for most internal repos and aptly if you want a snapshot-based workflow for staged releases and rollbacks. Sign the repo with an Ed25519 key, or an RSA key of at least 2048 bits, used only for this repo. Ship the public key and a .sources file to clients with Ansible or cloud-init. Then run apt policy <package> on a client to confirm the package really comes from your internal origin.

What Is a Custom APT Repository?

An APT repository is a directory tree served over HTTP(S). It holds .deb files under pool/ and index metadata under dists/. At the top of dists/<suite>/ sits the signed release metadata: InRelease (or Release plus a detached Release.gpg). APT downloads it and checks the signature against the public key in the client’s keyring.

It then verifies the hashes of every index file and package it downloads against the checksums listed in that signed metadata. A valid signature proves the metadata wasn’t altered and was signed by whoever holds the key; it says nothing about how securely the packages were built. A custom repo has the same structure. You just build it and hold the signing key.

What about copying .deb files around?

You can scp a .deb and run dpkg -i. That works for one machine. It falls apart across a fleet:

  • No dependency resolution. dpkg -i won’t pull in missing dependencies. apt install will, as long as clients can also reach a repository that carries them: the regular Ubuntu archive or a mirror of it, or your internal repo if you publish the dependencies there too.
  • No upgrade path. Servers don’t know a new version exists until you push it again. With a repo, apt upgrade and unattended-upgrades handle it.
  • No integrity check. A signed repo proves the metadata and packages were published by whoever holds your signing key and weren’t changed in transit. It doesn’t prove the package was built securely; that’s still your build process’s job.
  • Firewalled fleets keep working. The repo lives on your network, so installs don’t need outbound internet.
  • Patched or pinned builds. You can ship a CVE backport before the distro mirror has it. Configured servers can then converge on the exact build you tested, subject to your pinning, package holds and update policy.

Why apt-key is out

Older tutorials run apt-key add. That command put every key into a global trusted keyring. Any key in that keyring could sign any repository on the system. So a compromised third-party key could vouch for packages that pretend to come from somewhere else.

The replacement is simple. Store each repo’s public key in its own file under /etc/apt/keyrings/. Then reference that exact file with Signed-By in the repo definition. Now the key only counts for that one repo. Canonical’s third-party repository guidance and the Ubuntu Server package management docs cover this model. Ubuntu 24.04 also keeps its own sources in deb822 format by default, in /etc/apt/sources.list.d/ubuntu.sources (see the deb822-by-default spec and the 24.04 release notes). Your internal repo should follow the same pattern.

reprepro vs aptly vs dpkg-scanpackages: which one?

All three are free and open source and available from the Ubuntu archive. dpkg-scanpackages and apt-ftparchive come from the dpkg-dev and apt-utils packages; reprepro and aptly are separate packages you install the same way.

ToolBest forStrengthsWeak spots
repreproMost internal repos: tools, agents, patched packagesOne config file, signs and exports automatically on every change, multiple distributions (noble + jammy) in one treeKeeps only one version of a package per distribution/component/architecture by default, so there are no built-in rollbacks
aptlyTeams that want staged releases and rollbacksSnapshot-based workflow with publish switch for staged releases, can merge and mirror upstream reposMore concepts to learn (repos, snapshots, publishes), larger on-disk footprint
dpkg-scanpackages / apt-ftparchiveA few packages, a lab, or a quick static repoInstallable via dpkg-dev and apt-utils, no daemon, no databaseYou write the scripting yourself: Release file, signing, cleanup. No pool management, and it’s easy to ship an unsigned repo by accident

My recommendation: start with reprepro. Move to aptly when you need “roll the whole fleet back to last Tuesday’s package set.” Use dpkg-scanpackages only for small, throwaway setups.

Prerequisites

  • A repository server running Ubuntu 24.04 LTS (Noble Numbat). A small VM is fine, and so is a low-power mini PC in a homelab.
  • One or more clients on Ubuntu 24.04 LTS. Ubuntu 22.04 LTS clients also work with this pattern, since their APT supports deb822 .sources and Signed-By.
  • sudo access on the repo server and the clients
  • gnupg installed on the repo server (install it with sudo apt install gnupg if it isn’t already present)
  • An internal DNS name for the repo server, such as apt.internal.example, or /etc/hosts entries on clients
  • A network path from clients to the repo server on TCP 80 (or 443 for HTTPS)
  • At least one .deb to publish. Step 2 builds a test package if you don’t have one yet.
  • Optional: Ansible or cloud-init for fleet rollout (Step 9)
RequirementDetails
Repo server OSUbuntu 24.04 LTS
Client OSUbuntu 24.04 LTS or 22.04 LTS
Signing keyRSA ≥ 2048 bits, or Ed25519/Ed448
Web servernginx from the Ubuntu archive
DiskEnough for your packages plus metadata. Put the repo on an SSD if it holds large binaries.

Note on key strength: The Ubuntu 24.04 release notes state that APT requires repository signatures from RSA keys of at least 2048 bits, or Ed25519/Ed448 keys. 1024-bit RSA is deprecated; APT currently warns about it, with full rejection planned after affected repositories are re-signed with stronger keys. If you reuse an old signing key, check its size first.

Environment used here: Ubuntu 24.04 LTS on both the server and the clients, with packages from the Ubuntu archive. Example names: repo host apt.internal.example, repo root /srv/apt, package tbrt-hello. Replace them with your own.

Step-by-Step Guide

Step 1: Generate a Dedicated Signing Key

Do this on the repo server, or on a separate build host that publishes to it. The key should sign this repository and nothing else. If it’s ever compromised or rotated, no other systems are affected.

Run the interactive generator:

gpg --full-generate-key

At the prompts, choose:

  • Key type: an ECC sign-only key on Curve 25519 (Ed25519). The menu wording and numbering differ between GnuPG versions (Ubuntu 24.04 ships GnuPG 2.4), so read the labels; if your menu doesn’t offer a matching choice, use the scripted command below, which names ed25519 explicitly.
  • Expiry: something like 2y. Expiring keys force you to practice rotation.
  • Name: Internal APT Signing Key
  • Email: apt-signing@example.internal

If you’d rather script it, --quick-generate-key does the same thing in one line:

# ed25519 = key algorithm; sign = signing capability only; 2y = expires in 2 years
gpg --quick-generate-key "Internal APT Signing Key <apt-signing@example.internal>" ed25519 sign 2y

About the passphrase: reprepro and aptly sign every time you publish. If the key has a passphrase, gpg-agent has to unlock it. That gets awkward in cron jobs and CI. You have two options:

  • Use a passphrase and unlock gpg-agent before you publish. This is safer and fine if a human runs the publishes.
  • Use no passphrase on a locked-down build host. It’s handy for automation, but anyone with that user account can sign packages your fleet will trust, which makes that host a high-value target.

For automation, prefer keeping the passphrase and supplying it only at publish time: store it in your CI secret store and preload it into gpg-agent (gpg-preset-passphrase, which needs allow-preset-passphrase in gpg-agent.conf), or keep the signing key on a dedicated, access-restricted signing host or hardware token so ordinary build hosts never hold it. Treat a passphrase-less key as the fallback, not the default.

For option 2, generate the key like this:

# --batch --pinentry-mode loopback --passphrase '' creates the key with no passphrase
# without prompting; use only on a hardened build host
gpg --batch --pinentry-mode loopback --passphrase '' --quick-generate-key "Internal APT Signing Key <apt-signing@example.internal>" ed25519 sign 2y

--pinentry-mode loopback makes GnuPG take the passphrase from the command line instead of asking pinentry, which keeps the command non-interactive across GnuPG 2.x configurations. Later signing runs should then complete without a passphrase prompt.

Now get the fingerprint:

gpg --list-secret-keys --keyid-format=long apt-signing@example.internal

Example output (illustrative; your key ID, fingerprint and dates will differ):

sec   ed25519/0A1B2C3D4E5F6071 2026-10-23 [SC] [expires: 2028-10-22]
      9F3C1E2D4B5A69788776655443322110A1B2C3D4
uid                 [ultimate] Internal APT Signing Key <apt-signing@example.internal>

The 40-character line is the fingerprint. The rest of this guide calls it YOUR_KEY_FINGERPRINT.

Export the armored public key. Clients will get this file:

# --armor writes ASCII text (.asc) instead of binary
gpg --armor --export YOUR_KEY_FINGERPRINT > ~/internal-repo.asc

Back up the private key to offline storage, such as an encrypted USB drive or your secrets vault. Don’t keep the backup on the repo server itself:

gpg --armor --export-secret-keys YOUR_KEY_FINGERPRINT > ~/internal-repo-PRIVATE.asc

Warning: The private key must never reach client machines. Clients only ever need the public .asc file. Delete ~/internal-repo-PRIVATE.asc from the server once it’s backed up. GnuPG also saves a revocation certificate in ~/.gnupg/openpgp-revocs.d/, so back that up as well.

Output of gpg --list-secret-keys --keyid-format=long apt-signing@example.internal showing an ed25519 [SC] signing key with a 40-character fingerprint and the uid Internal APT Signing Key <apt-signing@example.internal>, with no subkey

Step 2: Build a Test Package (Optional)

If you already have .deb files, skip this step. Otherwise, build a tiny package so you can test the whole pipeline:

mkdir -p ~/build/tbrt-hello_1.0.0_all/DEBIAN ~/build/tbrt-hello_1.0.0_all/usr/bin

cat > ~/build/tbrt-hello_1.0.0_all/DEBIAN/control <<'EOF'
Package: tbrt-hello
Version: 1.0.0
Section: utils
Priority: optional
Architecture: all
Maintainer: Ops Team <ops@example.internal>
Description: Test package for the internal APT repository
 Prints a message to confirm the internal repo works.
EOF

printf '#!/bin/sh\necho "Hello from the internal APT repo"\n' > ~/build/tbrt-hello_1.0.0_all/usr/bin/tbrt-hello
chmod 0755 ~/build/tbrt-hello_1.0.0_all/usr/bin/tbrt-hello

# --root-owner-group makes files owned by root:root inside the package
dpkg-deb --build --root-owner-group ~/build/tbrt-hello_1.0.0_all

Example output (illustrative; exact wording varies by reprepro version):

dpkg-deb: building package 'tbrt-hello' in '/home/youruser/build/tbrt-hello_1.0.0_all.deb'.

Step 3 (Option A): Build the Repository with reprepro

This is the recommended path for most readers. Install reprepro:

sudo apt update
sudo apt install -y reprepro

Create the repo root and make your admin user the owner. That user’s GnuPG keyring holds the signing key:

sudo install -d -o "$USER" -g "$USER" -m 0755 /srv/apt /srv/apt/conf

Create the distributions config:

# /srv/apt/conf/distributions
Origin: Internal
Label: Internal
Suite: noble
Codename: noble
Architectures: amd64 arm64
Components: main
Description: Internal packages for Ubuntu 24.04
SignWith: YOUR_KEY_FINGERPRINT

Origin: Internal
Label: Internal
Suite: jammy
Codename: jammy
Architectures: amd64 arm64
Components: main
Description: Internal packages for Ubuntu 22.04
SignWith: YOUR_KEY_FINGERPRINT

What the fields do:

  • Origin and Label show up in apt policy and pin files. They’re how you identify and pin packages from this repo later. They’re labels, not proof: anyone can type the same values, so trust comes from the Signed-By key, not from these fields.
  • Codename becomes the directory under dists/. It must match Suites: on the client.
  • SignWith tells reprepro which key signs InRelease and Release.gpg.
  • The blank line between the stanzas is required.

Drop the jammy stanza if you only run 24.04. Add optional defaults:

# /srv/apt/conf/options
verbose
basedir /srv/apt

Add the package to the noble distribution:

# -b sets the base directory; includedeb <codename> <file> adds a binary package
reprepro -b /srv/apt includedeb noble ~/build/tbrt-hello_1.0.0_all.deb

reprepro copies the file into pool/, rebuilds the indexes, and signs the Release metadata in one go. Over SSH, gpg-agent may fail with Inappropriate ioctl for device when it needs a passphrase. Run export GPG_TTY=$(tty) and try again.

Confirm the package is listed:

reprepro -b /srv/apt list noble

Because tbrt-hello is Architecture: all, it’s a single package file, not two separate builds. reprepro treats it as available to every architecture configured for noble — here, both amd64 and arm64 — so clients on either architecture can install it.

The exact text and formatting of reprepro list output has changed across versions, so check what your own installed version prints rather than taking this guide’s wording as gospel. Treat the block below as an illustration only. With this configuration you may see the package listed once per configured architecture, like this; what matters is that tbrt-hello appears at version 1.0.0 for the architectures your clients use:

noble|main|amd64: tbrt-hello 1.0.0
noble|main|arm64: tbrt-hello 1.0.0

Check that the signed metadata exists:

ls /srv/apt/dists/noble/

InRelease Release Release.gpg main

reprepro includedeb noble adding tbrt-hello_1.0.0_all.deb, followed by reprepro list noble showing the package for amd64 and arm64, and ls of dists/noble showing InRelease, Release, Release.gpg

Want a reference? The OpenDev project’s reprepro documentation shows how a large production setup runs reprepro.

Step 3 (Option B): Build the Repository with aptly

Choose aptly if you want a snapshot-based workflow. aptly builds a local repo, lets you take a snapshot of its contents, and publishes that snapshot. Moving to a different package set, including an earlier one, is a matter of switching the published distribution to a different snapshot.

sudo apt update
sudo apt install -y aptly

By default aptly keeps its data under ~/.aptly. Move it somewhere nginx can read.

Run aptly config show once. If no config file exists yet, this creates ~/.aptly.conf with aptly’s defaults and prints the resulting JSON to your terminal:

aptly config show

Edit ~/.aptly.conf and add or change the rootDir key:

{
    "rootDir": "/srv/aptly"
}

Create the directory. It needs to be owned by whichever user runs aptly publish, since aptly creates public/ underneath it:

sudo install -d -o "$USER" -g "$USER" -m 0755 /srv/aptly

Before you create any repos or snapshots, confirm aptly actually picked up the change:

aptly config show

Check that the output now shows “rootDir”: “/srv/aptly”. Every aptly command in the rest of this guide assumes that same config file and rootDir. If you later run aptly as a different user, from cron, or with an explicit -config= flag, point it at this same file — otherwise you’ll end up with a second, empty-looking aptly data directory and wonder where your repo went.

Also check that the directory is actually usable for publishing: the user running aptly publish needs write access to /srv/aptly, and once aptly creates /srv/aptly/public/, nginx’s own user (commonly www-data) needs read and traverse access to it. If nginx and aptly run as different users, you may need group permissions or a chmod o+rx on the parent directories rather than relying on the 0755 from the command above.

Create a local repo, add packages, take a snapshot, and publish it:

# -distribution and -component set defaults used when publishing
aptly repo create -distribution=noble -component=main internal-noble

aptly repo add internal-noble ~/build/tbrt-hello_1.0.0_all.deb

# Name snapshots by date so you can tell them apart later
aptly snapshot create internal-noble-2026-10-23 from repo internal-noble

# -gpg-key picks the signing key; -architectures sets what gets published
aptly publish snapshot -distribution=noble -architectures=amd64,arm64 -gpg-key=YOUR_KEY_FINGERPRINT internal-noble-2026-10-23

The published tree ends up in /srv/aptly/public/. Confirm it’s actually there and readable before moving on:

ls -la /srv/aptly/public/

When you add packages later, create a new snapshot. Then switch the published distribution to it:

aptly repo add internal-noble ~/build/tbrt-hello_1.0.1_all.deb
aptly snapshot create internal-noble-2026-10-30 from repo internal-noble
aptly publish switch -gpg-key=YOUR_KEY_FINGERPRINT noble internal-noble-2026-10-30

To move back to an earlier package set, run publish switch again with the older snapshot name.

Tip: aptly’s flags differ between releases. Before you script any of this, check aptly help publish and the aptly documentation against the version you have installed. If aptly can’t find your key, look at the gpgProvider setting in ~/.aptly.conf. It controls whether aptly calls gpg or gpg2.

aptly snapshot create and aptly publish snapshot commands completing, with aptly reporting the published distribution noble and its architectures

Step 3 (Option C): Static Repo with dpkg-scanpackages and apt-ftparchive

This option suits a handful of packages in a lab. It creates a flat repository: one directory, no dists/ tree, and no components.

sudo apt install -y dpkg-dev apt-utils
sudo install -d -o "$USER" -g "$USER" -m 0755 /srv/apt-flat
cp ~/build/*.deb /srv/apt-flat/
cd /srv/apt-flat

# --multiversion keeps every version found; /dev/null means no override file
dpkg-scanpackages --multiversion . /dev/null > Packages
gzip -9kf Packages   # -k keeps the uncompressed copy

# Generate a Release file with checksums, then sign it two ways
apt-ftparchive release . > Release
gpg --local-user YOUR_KEY_FINGERPRINT --clearsign -o InRelease Release
gpg --local-user YOUR_KEY_FINGERPRINT -abs -o Release.gpg Release

# Confirm both signatures were made with the key you expect
gpg --verify InRelease
gpg --verify Release.gpg Release

Pass the full 40-character fingerprint to --local-user so GnuPG can’t pick a different secret key that matches a shorter ID or the same email address. Check that both gpg --verify results show that same fingerprint.

You rerun every one of those commands each time a package changes. That’s where the limits show up:

  • You script signing, cleanup, and multi-distribution support yourself.
  • Nothing stops you from forgetting to re-sign. Clients will then reject the stale signature.
  • Old .deb files pile up until you delete them by hand.
  • It’s tempting to skip signing and set Trusted: yes on clients. Don’t. That turns off signature checks for the repo entirely.

For a flat repo, the client .sources file uses Suites: ./ and leaves out Components:. The sources.list(5) manual page documents this form: a suite can be an exact path, in which case components must be omitted and the suite must end with a slash.

URIs must point at the directory that holds Packages and InRelease, so serve /srv/apt-flat as the web root (Step 4). Step 6 shows the full client file. After the first apt update on a client, confirm it fetched InRelease and Packages from that URI with no signature or 404 errors before you rely on it.

Step 4: Serve the Repository with nginx

The repo is just static files, so any web server works. nginx is light and simple to configure:

sudo apt install -y nginx

Publish the public key next to the repo so clients can fetch it:

cp ~/internal-repo.asc /srv/apt/internal-repo.asc

Create a server block. For aptly, set root /srv/aptly/public; instead. For the flat repo from Option C, set root /srv/apt-flat;.

# /etc/nginx/sites-available/apt-repo
server {
    listen 80;
    server_name apt.internal.example;

    root /srv/apt;
    autoindex on;   # directory listings help debugging; turn off if you prefer

    # reprepro's conf/ and db/ directories are internal state, not for clients
    location ~ ^/(conf|db)/ {
        deny all;
    }
}

Enable the site, test the config, and reload nginx:

sudo ln -s /etc/nginx/sites-available/apt-repo /etc/nginx/sites-enabled/apt-repo
sudo nginx -t
sudo systemctl reload nginx

Example output from nginx -t:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now restrict access to your internal network with UFW.

Warning: If UFW isn’t enabled yet, allow SSH before you run ufw enable. Otherwise you’ll lock yourself out of a remote server.

sudo ufw allow OpenSSH
# Only allow internal subnets to reach the repo; adjust to your network
sudo ufw allow from 10.0.0.0/8 to any port 80 proto tcp
sudo ufw enable
sudo ufw status

HTTP or HTTPS? The GPG signature protects the integrity of the repository metadata and the packages it lists, so a tampered package fails verification even over plain HTTP. HTTP still leaves other exposure: anyone on the path can see which packages and versions each host downloads, and can block, delay or redirect requests to disrupt updates.

HTTPS with a certificate from your internal CA closes most of that and also protects the first download of the public key if clients fetch it from this server. Prefer HTTPS where you can. Plain HTTP on a segmented internal network is a trade-off you should choose deliberately, not a free default.

Test from a client:

curl -I http://apt.internal.example/dists/noble/InRelease

HTTP/1.1 200 OK

nginx -t reporting syntax ok, followed by curl -I against /dists/noble/InRelease returning HTTP/1.1 200 OK

Step 5: Install the Public Key on a Client

On each client, create the keyrings directory and download the public key:

# -d creates a directory; -m 0755 makes it world-readable so apt can read it
sudo install -d -m 0755 /etc/apt/keyrings
sudo wget -qO /etc/apt/keyrings/internal-repo.asc http://apt.internal.example/internal-repo.asc
sudo chmod 0644 /etc/apt/keyrings/internal-repo.asc

Fetching a key over the same channel it’s meant to protect is a bootstrap shortcut. Verify the fingerprint against the one you noted in Step 1:

gpg --show-keys /etc/apt/keyrings/internal-repo.asc
pub   ed25519 2026-10-23 [SC] [expires: 2028-10-22]
      9F3C1E2D4B5A69788776655443322110A1B2C3D4
uid                      Internal APT Signing Key <apt-signing@example.internal>

For a fleet, ship the key file with configuration management instead (Step 9). Trust then comes from your Ansible repo or cloud-init user data.

APT reads armored keys straight from files ending in .asc. If you prefer the binary format, convert it with gpg --dearmor and use a .gpg filename.

Step 6: Create the deb822 .sources File

Older guides get this file wrong. Create /etc/apt/sources.list.d/internal-repo.sources:

# /etc/apt/sources.list.d/internal-repo.sources
Types: deb
URIs: http://apt.internal.example
Suites: noble
Components: main
Signed-By: /etc/apt/keyrings/internal-repo.asc

To write the file with the client’s own codename filled in (works on both 24.04 and 22.04):

sudo tee /etc/apt/sources.list.d/internal-repo.sources > /dev/null <<EOF
Types: deb
URIs: http://apt.internal.example
Suites: $(. /etc/os-release && echo "$VERSION_CODENAME")
Components: main
Signed-By: /etc/apt/keyrings/internal-repo.asc
EOF

Each field has a job:

  • URIs points at the repository root, the directory that contains dists/. Don’t point it at dists/ itself.
  • Suites must match a published codename (noble or jammy).
  • Components must match a published component (main).
  • Signed-By binds this repo to this one key file. Only that key can sign it.

For the flat repo from Option C, use:

Types: deb
URIs: http://apt.internal.example/
Suites: ./
Signed-By: /etc/apt/keyrings/internal-repo.asc

Step 7: Update and Verify with apt policy

Refresh the package lists:

sudo apt update

Look for your repo in the output, with no warnings or errors attached to it:

Get:5 http://apt.internal.example noble InRelease [2,512 B]
Get:6 http://apt.internal.example noble/main amd64 Packages [412 B]

Now the step most tutorials skip: prove where the package resolves from.

apt policy tbrt-hello

tbrt-hello:
Installed: (none)
Candidate: 1.0.0
Version table:
1.0.0 500
500 http://apt.internal.example noble/main amd64 Packages

The candidate version comes from your internal URI at the default priority of 500. Next, check the origin metadata APT parsed:

apt-cache policy

Find the block for your repo:

500 http://apt.internal.example noble/main amd64 Packages
release v=,o=Internal,a=noble,n=noble,l=Internal,c=main,b=amd64
origin apt.internal.example

o=Internal and l=Internal come from your conf/distributions. Seeing them confirms APT parsed and indexed your Release metadata. They don’t prove which key signed it: the signature check is the apt update run above, which must finish with no NO_PUBKEY, EXPKEYSIG or “is not signed” errors for this repo. Check the key itself separately with gpg --show-keys /etc/apt/keyrings/internal-repo.asc and compare the fingerprint with the one from Step 1. Install the package and run it:

sudo apt install -y tbrt-hello
tbrt-hello

Hello from the internal APT repo

apt policy tbrt-hello showing Candidate 1.0.0 from http://apt.internal.example noble/main with priority 500, followed by apt-cache policy output showing release o=Internal,l=Internal,n=noble

Step 8: Pin Internal Packages Above Public Mirrors

This matters when you ship a patched build of a package that also exists in the Ubuntu archive. APT installs the highest version among sources with the same priority. If Ubuntu publishes a higher version number than your build, Ubuntu wins.

Pin your origin for the packages you override:

# /etc/apt/preferences.d/internal-repo.pref
Package: tbrt-hello
Pin: release o=Internal
Pin-Priority: 990

How priorities behave:

Pin-PriorityEffect
100Installed packages stay put, but new installs prefer other sources
500Default for normal repos
990Preferred over priority-500 repos even when their version is higher, unless the installed version is already newer
> 1000Preferred even if it means downgrading an installed package

Avoid Package: * with a high priority unless you mean it. Any package in your repo with a colliding name would then shadow Ubuntu’s version. After you add the pin, run apt policy tbrt-hello again. The internal line should show 990. Candidate selection still follows APT’s rules: a 990 pin won’t downgrade a newer version that is already installed (that takes a priority above 1000), so check apt policy on a real client before you count on it.

Step 9: Roll Out to the Fleet with Ansible or cloud-init

Neither of these is a Canonical-documented workflow for internal repos. They’re common patterns for distributing the same two files: the key and the .sources file. Adapt them to your setup.

Ansible playbook:

# internal-repo.yml
- name: Configure internal APT repository
  hosts: ubuntu_servers
  become: true
  tasks:
    - name: Ensure keyrings directory exists
      ansible.builtin.file:
        path: /etc/apt/keyrings
        state: directory
        mode: "0755"

    - name: Install internal repo public key
      ansible.builtin.copy:
        src: files/internal-repo.asc   # committed to your Ansible repo
        dest: /etc/apt/keyrings/internal-repo.asc
        mode: "0644"

    - name: Install deb822 source definition
      ansible.builtin.copy:
        dest: /etc/apt/sources.list.d/internal-repo.sources
        mode: "0644"
        content: |
          Types: deb
          URIs: http://apt.internal.example
          Suites: {{ ansible_distribution_release }}
          Components: main
          Signed-By: /etc/apt/keyrings/internal-repo.asc

    - name: Refresh cache and install internal tooling
      ansible.builtin.apt:
        name: tbrt-hello
        state: latest
        update_cache: true

Run it:

ansible-playbook -i inventory.ini internal-repo.yml

Recent ansible-core releases also include an ansible.builtin.deb822_repository module. Older ansible-core versions, such as those packaged on older distributions, don’t have it, so run ansible-doc ansible.builtin.deb822_repository to confirm your version has it before you switch.

cloud-init, for new VMs:

#cloud-config
write_files:
  - path: /etc/apt/keyrings/internal-repo.asc
    permissions: "0644"
    content: |
      -----BEGIN PGP PUBLIC KEY BLOCK-----
      (paste the full contents of internal-repo.asc here)
      -----END PGP PUBLIC KEY BLOCK-----
  - path: /etc/apt/sources.list.d/internal-repo.sources
    permissions: "0644"
    content: |
      Types: deb
      URIs: http://apt.internal.example
      Suites: noble
      Components: main
      Signed-By: /etc/apt/keyrings/internal-repo.asc

package_update: true
packages:
  - tbrt-hello

In cloud-init’s default module order, write_files runs in an earlier stage than package installation, so the repo is normally in place when package_update runs. Images can change that order, so check the first boot with cloud-init status --long and /var/log/cloud-init-output.log. Verify the pasted key’s fingerprint with gpg --show-keys before you bake it into user data.

Step 10: The Routine for Every New Package

This is your release checklist from now on:

  • Bump the version in DEBIAN/control. APT ignores a package whose version it already has.
  • Publish it:
    • reprepro: reprepro -b /srv/apt includedeb noble ./yourpkg_1.0.1_all.deb. It signs and exports automatically.
    • aptly: repo add, then snapshot create, then publish switch.
    • dpkg-scanpackages: rerun the whole Option C block, signing included.
  • Verify on the server: reprepro -b /srv/apt list noble, or check dists/noble/main/binary-amd64/Packages.
  • Refresh clients: run sudo apt update or wait for their next scheduled update. Then check apt policy yourpkg on one canary host before rolling out wider.

Want unattended-upgrades to install internal updates? Add your origin to /etc/apt/apt.conf.d/50-unattended-upgrades under Unattended-Upgrade::Origins-Pattern, for example "origin=Internal,codename=${distro_codename}";.

Configuration Reference

SettingWhereExampleNotes
Codename / Suiteconf/distributionsnobleMust match Suites: on clients
Componentsconf/distributionsmainMust match Components: on clients
Architecturesconf/distributionsamd64 arm64Clients on unlisted architectures won’t see packages
SignWithconf/distributionsFingerprintUse the full fingerprint, not a short ID
Origin / Labelconf/distributionsInternalUsed by apt policy, pin files, unattended-upgrades
URIsclient .sourceshttp://apt.internal.exampleRepository root, the directory containing dists/
Signed-Byclient .sources/etc/apt/keyrings/internal-repo.ascA path, or an inline armored key block
Pin / Pin-Priority/etc/apt/preferences.d/*.prefrelease o=Internal / 990Forces internal builds over public mirrors

Tips and Troubleshooting

NO_PUBKEY or “The following signatures couldn’t be verified”

Why it happens: The key file is missing or unreadable, the Signed-By path doesn’t match the real file, or the repo was signed with a different key.

Fix:

  • Check the file: ls -l /etc/apt/keyrings/internal-repo.asc. It should be -rw-r--r--.
  • Check the fingerprint with gpg --show-keys /etc/apt/keyrings/internal-repo.asc and compare it to SignWith.
  • Make sure Signed-By: contains the exact path, extension included.
  • Run sudo apt update again.

Don’t “fix” this with apt-key add. That brings back the global trust problem you’re trying to avoid.

“The repository … does not have a Release file”

Why it happens: Suites or Components don’t match what was published, URIs points at the wrong level, or the metadata was never generated.

Fix: Open http://apt.internal.example/dists/ in a browser or with curl. You should see a noble/ directory containing InRelease. If dists/ itself returns 404, URIs is wrong. If noble is missing, check Codename in conf/distributions and run reprepro -b /srv/apt export.

“Malformed stanza” or parse errors in the .sources file

Why it happens: A one-line deb http://... entry ended up inside a .sources file, a field name is misspelled, or two stanzas aren’t separated by a blank line.

Fix: Use one field per line with exact names: Types, URIs, Suites, Components, Signed-By. One-line deb syntax only belongs in legacy .list files.

“Conflicting values set for option Signed-By”

Why it happens: The same repository URI is defined twice with different keys. Often it’s once in an old .list file and once in your new .sources file.

Fix: Search with grep -r apt.internal.example /etc/apt/sources.list /etc/apt/sources.list.d/ and delete the duplicate.

Signature rejected as a weak algorithm

Why it happens: The repo is signed with a 1024-bit RSA key, which Ubuntu 24.04’s APT flags as weak and will eventually reject once affected repositories have had time to re-sign with stronger keys. The 24.04 release notes document this. The exact warning text varies by APT version.

Fix: Generate a new Ed25519 key, or an RSA key of at least 2048 bits (Step 1), update SignWith, re-export, and distribute the new public key.

NO_PUBKEY comes back after a key rotation

Why it happens: The server now signs with the new key, but clients only trust the old one.

Fix: Push the new public key to all clients before you switch SignWith. A single .asc file can hold both public keys during the overlap. Confirm every host actually has the combined keyring (for example, compare the file’s checksum across the fleet with your configuration management tool) before you change anything on the server.

Then switch signing, run gpg --verify against the published InRelease to confirm it now shows the new fingerprint, and run apt update on a few canary hosts before the rest of the fleet. Keep the old private key until the rollout is confirmed, so you can switch SignWith back if some hosts missed the new key. Remove the old public key only once every host has the new one. In larger fleets, some teams package the keyring itself (an internal-archive-keyring .deb) and ship rotations through the repo.

New package published, but apt install can’t find it

Why it happens: The index wasn’t regenerated, the architecture isn’t published, or the client hasn’t refreshed.

Fix: Run reprepro -b /srv/apt list noble on the server. With aptly, confirm the new snapshot is the one published. Check that the client’s architecture (dpkg --print-architecture) is listed in Architectures. Then run sudo apt update on the client.

apt policy shows the public mirror winning

Why it happens: Ubuntu’s archive has a higher version number at the same priority.

Fix: Add a pin as in Step 8, or version your builds so they sort above upstream. For example, 3.0.13-0ubuntu3.4+internal1 sorts above 3.0.13-0ubuntu3.4.

nginx returns 403 for repo files

Why it happens: The www-data user can’t traverse into the repo directory. This is common when the repo lives under a home directory.

Fix: Keep the repo under /srv/. Make sure every parent directory is at least 0755 and files are 0644.

Quick tips

  • Audit what a client trusts: ls /etc/apt/keyrings/ /usr/share/keyrings/ shows the keys. grep -r Signed-By /etc/apt/sources.list.d/ shows which repo uses which key.
  • Embed the key inline: Signed-By: can hold the armored key block directly, with each line indented by one space. That leaves one file to distribute instead of two.
  • Put the repo server on a UPS. If your patch pipeline depends on this box, a power blip during a publish can leave half-written metadata.
  • Canary first: point one host at a staging codename or snapshot before you publish to the fleet.

Wrapping Up

You now have a signed internal APT repository. Clients trust it through one scoped key in /etc/apt/keyrings/, and apt policy proves packages come from your origin. After the initial setup, shipping a new build is one reprepro command or a snapshot-and-switch in aptly.

My take: reprepro covers what most teams need with the least to learn. Reach for aptly as soon as someone asks “can we roll back the whole package set?” Either way, don’t skip the apt policy check, because it’s the only step that proves the setup works.

StepActionApplies To
1Generate a dedicated Ed25519 (or RSA ≥2048-bit) signing keyRepo server
2–3Build the repo (reprepro, aptly, or dpkg-scanpackages)Repo server
4Serve with nginx, restrict access with UFWRepo server
5–6Install the key in /etc/apt/keyrings/, add a deb822 .sources fileClients (24.04 / 22.04)
7–8Verify with apt policy, pin if neededClients
9–10Roll out with Ansible/cloud-init, republish per releaseFleet

Resources