Solution:
Root Cause: Restrictive File Permissions Preventing _apt User Access In recent Debian and Ubuntu versions, APT drops root privileges when downloading and verifying package indexes, running unprivileged as the
_apt system user. If key files in
/etc/apt/keyrings/ or
/etc/apt/trusted.gpg.d/ are configured with restrictive permissions (e.g.,
0600 owned by
root:root),
_apt cannot read the public key, resulting in
NO_PUBKEY errors.
Diagnostic Verification: Check file permissions across system keyring paths:
Copy
bash
ls -la /etc/apt/keyrings/
ls -la /etc/apt/trusted.gpg.d/
Verify if permissions restrict world-readability (missing
r--r--r--).
Step-by-Step Fix: 1 Reset directory ownership to root:
sudo chown -R root:root /etc/apt/keyrings /etc/apt/trusted.gpg.d2 Ensure directories are executable and readable by all users:
sudo chmod 755 /etc/apt/keyrings /etc/apt/trusted.gpg.d3 Apply world-readable 0644 permissions to all key files:
sudo chmod 644 /etc/apt/keyrings/* /etc/apt/trusted.gpg.d/*4 Confirm APT update succeeds under the _apt unprivileged sandbox:
sudo apt updatePrevention & Long-Term Monitoring: Include explicit chmod 644 commands in automated setup scripts (Bash, Cloud-Init, Dockerfiles) after creating new keyring files.