Skip to content

Instantly share code, notes, and snippets.

@ghana7989
Created June 18, 2025 04:21
Show Gist options
  • Save ghana7989/817789feba7315e749ec47ff6ff22cc6 to your computer and use it in GitHub Desktop.
Save ghana7989/817789feba7315e749ec47ff6ff22cc6 to your computer and use it in GitHub Desktop.
GPG Agent restart script
function restart-gpg() {
echo "πŸ” Checking for GPG lock files..."
# Remove any existing lock files
if [ -d ~/.gnupg ]; then
find ~/.gnupg -name "*.lock" -delete 2>/dev/null
rm -f ~/.gnupg/public-keys.d/pubring.db.lock 2>/dev/null
echo "πŸ—‘οΈ Removed lock files"
fi
# Restart GPG agent
echo "πŸ”„ Restarting GPG agent..."
gpgconf --reload gpg-agent
# Test GPG
echo "πŸ§ͺ Testing GPG signing..."
if echo "test" | gpg --clearsign > /dev/null 2>&1; then
echo "βœ… GPG is working properly now!"
else
echo "❌ GPG is still having issues. You may need manual intervention."
fi
}
@ghana7989
Copy link
Author

I had to run this script to make the gpg work again if there is a sudden power cut to the system and abruptly system is shutdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment