Ubuntu error

Fixing “Couldn’t create temporary file” APT GPG Errors on Ubuntu/Debian

The Problem

If you’ve ever run sudo apt update and encountered a wall of errors like this:

Err:1 http://archive.ubuntu.com/ubuntu noble InRelease
  Couldn't create temporary file /tmp/apt.conf.XXXXXX for passing config to apt-key
W: An error occurred during the signature verification. The repository is not updated 
and the previous index files will be used. GPG error: http://archive.ubuntu.com/ubuntu 
noble InRelease: Couldn't create temporary file /tmp/apt.conf.XXXXXX for passing 
config to apt-key

You’re not alone. This frustrating error prevents APT from verifying package signatures, effectively blocking your ability to update or install software. The good news? It’s usually a simple fix.

🤓😎 More and more people are getting our Geek, Privacy, Dev & Lifestyle Tips

Want to receive the latest Geek, Privacy, Dev & Lifestyle blogs? Subscribe to our newsletter.

Understanding the Root Cause

APT (Advanced Package Tool) needs to create temporary files during the update process, particularly when verifying GPG signatures of repository metadata. These temporary files are typically created in /tmp, your system’s temporary file directory.

When APT can’t create these files, it’s usually due to one of three reasons:

  1. Incorrect permissions on /tmp (this was it in my case)
  2. Full /tmp directory 
  3. Read-only or corrupted filesystem 

The Quick Fix That Usually Works

In most cases, the /tmp directory has lost its special permissions. Here’s the one-liner that solves it:

sudo chmod 1777 /tmp

That’s it! This command restores the proper permissions to /tmp. But what does “1777” mean?

Understanding /tmp Permissions

The /tmp directory requires special permissions because it needs to be:

  • Writable by everyone (so any process can create temp files)
  • Secure (so users can’t delete each other’s files)

The permission 1777 breaks down as:

  • 1 – The “sticky bit” – ensures users can only delete their own files
  • 777 – Read, write, and execute permissions for everyone

You can verify the correct permissions with:

It should show: drwxrwxrwt (note the ‘t’ at the end, indicating the sticky bit).

When the Simple Fix Doesn’t Work

If fixing permissions doesn’t solve your problem, try these solutions in order:

1. Check Available Space

df -h /tmp

If /tmp is full (100% used), clean it up:

# Remove old temporary files (older than 24 hours)
sudo find /tmp -type f -atime +1 -delete

# Clear APT cache
sudo apt-get clean

2. Check if /tmp is Mounted Read-Only

mount | grep /tmp

If it shows “ro” (read-only), remount it:

sudo mount -o remount,rw /tmp

3. Use an Alternative Temporary Directory

If /tmp remains problematic, configure APT to use a different location:

# Create alternative temp directory
sudo mkdir -p /var/cache/apt/tmp
sudo chmod 1777 /var/cache/apt/tmp

# Configure APT to use it permanently
echo 'APT::ExtractTemplates::TempDir "/var/cache/apt/tmp";' | \
  sudo tee /etc/apt/apt.conf.d/99temp

4. Check Filesystem Health

For persistent issues, check your filesystem:

# Check for filesystem errors (may require reboot)
sudo fsck -f /

# Or simply reboot to clear any filesystem locks
sudo reboot

Prevention Tips

To avoid this issue in the future:

  1. Regular Updates: Keep your system updated to prevent accumulation of temporary files
  2. Monitor Disk Space: Use df -h periodically to check available space
  3. Automated Cleanup: Consider adding a cron job to clean old temp files:# Add to crontab with: crontab -e0 2 * * * find /tmp -type f -atime +7 -delete 2>/dev/null

Testing Your Fix

After applying any solution, test that APT works correctly:

sudo apt update
sudo apt upgrade

You should see normal repository updates without GPG errors.

Common Variations of This Error

This issue can manifest in slightly different ways:

  • Failed to fetch ... Couldn't create temporary file
  • GPG error: ... Couldn't execute 'apt-key'
  • W: Some index files failed to download

All of these typically stem from the same /tmp permission issue.

Conclusion

The “Couldn’t create temporary file” APT error is alarming when you first encounter it, but it’s usually just a permission problem that takes seconds to fix. The sudo chmod 1777 /tmp command resolves the issue in the vast majority of cases.

Remember: /tmp is a critical system directory that many applications rely on. Keeping it properly configured ensures smooth system operation beyond just APT updates.


Have you encountered this error? Did this solution work for you? Let me know in the comments below!

Quick Reference Card

# Diagnosis
ls -ld /tmp              # Check permissions
df -h /tmp               # Check space
mount | grep /tmp        # Check mount status

# Primary Fix
sudo chmod 1777 /tmp     # Restore proper permissions

# Verify Fix
sudo apt update          # Test APT functionality

Use at your own risk.

Last Updated on 18 September 2025

Leave a Comment

Your email address will not be published. Required fields are marked *

en_USEnglish
Scroll to Top