Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Ubuntu Git 每次 push/pull 都要輸入密碼?設定 credential.helper store 永久快取認證

編輯:關於 Linux

在 Ubuntu 使用 HTTPS 協定操作 Git 遠端倉庫時,每次 git push、git pull 都要求輸入帳號密碼,極大降低效率。透過 Git 內建的認證快取機制,可將憑證安全儲存於磁碟,避免重複輸入。

設定步驟

  1. 進入使用者家目錄:
cd ~
  1. 建立憑證檔案:
vim .git-credentials
  1. 輸入以下格式內容(請替換為您的實際資訊):
https://{username}:{password}@github.com
  1. 儲存離開後,啟用 store 認證助手:
git config --global credential.helper store
  1. 驗證設定生效:
cat ~/.gitconfig
# 應包含:
# [credential]
#     helper = store

替代方案:使用 SSH 協定

若不想以明文儲存密碼,建議改用 SSH:

  1. 產生 SSH 金鑰對:ssh-keygen -t ed25519
  2. 將公鑰加入 GitHub/GitLab/Gitea 等平台
  3. Clone 時使用 SSH URL:git clone git@github.com:user/repo.git

安全性提醒

  • .git-credentials 為明文儲存,請確保檔案權限 chmod 600 .git-credentials
  • 共用電腦或伺服器環境建議使用 SSH 或 cache --timeout=3600 限時快取模式
  • macOS/Windows 可使用 Keychain/Credential Manager 整合

設定完成後,後續 Git 操作將不再提示輸入密碼,大幅提升開發流暢度。

Copyright © Windows教程網 All Rights Reserved