Git长时间缓存超时设置失效问题求助(Ubuntu 18环境)
Hey there! Let's break down why your custom 200-hour Git credential cache is dying after just 10-12 hours on Ubuntu 18.04.
First, let's get clear on how the cache credential helper works:
- It stores credentials only in your system's memory, not on disk. That means the cache lives and dies with the background process that runs it.
- If that process gets killed for any reason, your cached credentials vanish immediately—no matter how long you set the timeout to be.
The Most Likely Culprits
Here's what's probably ending your cache early:
- Session Logouts/Restarts: If you log out of your Ubuntu desktop session, or your GNOME environment restarts (say, after a screen lock timeout that forces a refresh), the cache process gets terminated. Even if you log back in, the cache won't come back.
- System Memory Management: Ubuntu's Out-of-Memory (OOM) killer is designed to terminate low-priority processes when your system runs short on RAM. The Git cache process is pretty low-priority, so it might get axed after 10+ hours if your system is under memory pressure.
- Old Git Version Limits: Ubuntu 18.04 ships with Git 2.17 by default, which is a bit dated. While there's no official documented timeout limit for the
cachehelper, older versions might have unadvertised caps that override your huge timeout value. This is less likely than the first two issues, but it's worth checking.
Fixes for Long-Term Credential Storage
If you want credentials that stick around longer than a single session, ditch the cache helper and use a disk-based alternative:
Use Ubuntu's System Keyring (Recommended):
Thelibsecrethelper integrates with Ubuntu's GNOME Keyring, which securely stores credentials on disk and persists across sessions. To set it up:- Install the required packages first:
sudo apt-get install libsecret-1-0 libsecret-1-dev - Build the helper (it's included with Git but not installed by default):
cd /usr/share/doc/git/contrib/credential/libsecret sudo make - Set it as your default credential helper:
git config --global credential.helper libsecret
Now your GitHub credentials will be saved securely in your keyring and won't time out unless you explicitly remove them.
- Install the required packages first:
Use the
storeHelper (Plain Text, Less Secure):
If you don't mind storing credentials in a plain text file (and your home directory is encrypted, which Ubuntu 18.04 supports during setup), you can use thestorehelper:git config --global credential.helper 'store --file ~/.git-credentials'This saves your credentials to
~/.git-credentials—just make sure only you can read the file (Git sets the correct permissions automatically, but double-check withls -l ~/.git-credentials).
Verify Your Setup
To confirm which credential helper is active, run:
git config --global --get credential.helper
Make sure it's set to libsecret or store (not cache) if you want long-term persistence.
内容的提问来源于stack exchange,提问作者Kent Milder

