You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git长时间缓存超时设置失效问题求助(Ubuntu 18环境)

Why Your Git Credential Cache Is Timing Out So Early

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 cache helper, 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):
    The libsecret helper integrates with Ubuntu's GNOME Keyring, which securely stores credentials on disk and persists across sessions. To set it up:

    1. Install the required packages first:
      sudo apt-get install libsecret-1-0 libsecret-1-dev
      
    2. Build the helper (it's included with Git but not installed by default):
      cd /usr/share/doc/git/contrib/credential/libsecret
      sudo make
      
    3. 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.

  • Use the store Helper (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 the store helper:

    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 with ls -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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:55:21