Keep package sources authentic by configuring repository GPG keys and signing verification for apt repositories. 16.11.2025 | reading time: 2 min Signing repository metadata with GPG keys prevents tampering and proves authenticity; this short guide shows how to configure repository GPG keys for apt and highlights pitfalls to avoid. Quick Example: Apt Repository Follow these commands to import a repository GPG key, place it in the system keyring, add the repo using signed-by, and run an update; the example uses a fictional repo and shows expected output. ```bash # Import and dearmor the key into a managed keyring curl -fsSL https://repo.example.org/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/example-archive-keyring.gpg # Add the repository and point signed-by to the keyring echo "deb [signed-by=/usr/share/keyrings/example-archive-keyring.gpg] https://repo.example.org/debian stable main" | sudo tee /etc/apt/sources.list.d/example.list > /dev/null # Update package lists and observe verification messages sudo apt update # Expected excerpt of output: # Hit:1 https://repo.example.org/debian stable InRelease # Reading package lists... Done # Building dependency tree # Reading state information... Done ``` Things to Watch Store dearmored keys under /usr/share/keyrings for apt, avoid the deprecated apt-key when possible, use the sources.list signed-by option to pin a key to a repo, rotate and expire keys proactively, and automate rotation with configuration management to reduce human error. Complementary Tools Manage and inspect keys with gpg, verify detached signatures with gpgv, and on RPM-based systems use rpm --import or rpmkeys and dnf config-manager; consider debsig-verify for package signature policies and integrate checks into CI pipelines. Next Steps Start by applying the example to a test server, then build procedures for key rotation and incident response so repository compromise can be contained; learn more about Linux security and consider certification paths like CompTIA Linux+ or LPIC-1, with bitsandbytes.academy offering intensive exam preparation. Join Bits & Bytes Academy First class LINUX exam preparation. security setup utilities infrastructure