[英]How can I store Github token with Git Credential Manager on Ubuntu?
[英]How to use Git credential store on WSL (Ubuntu on Windows)?
我嘗試按照以下說明操作: https : //stackoverflow.com/a/40312117/21728基本上是這樣做的:
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
但是當我做任何網絡操作時,我得到這個錯誤:
** (process:7902): CRITICAL **: could not connect to Secret Service: Cannot autolaunch D-Bus without X11 $DISPLAY
我猜這是合乎邏輯的,因為確實沒有 X11 顯示器。
如何使 Git 憑據緩存在 Windows (WSL) 上的 Ubuntu 上工作?
如果您為 Windows 安裝了 Git,則您的系統上會安裝一個 Windows 集成憑據管理器。
您可以從WSL如發現運行Windows可執行文件在這里。
要使用它,您可以運行以下命令(假設您的 git for windows 安裝在 C:\\Program Files\\Git 上)
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"
我已經創建了一個腳本來為你做這件事。 我將它與我的 Chef 編排一起使用。
cmd.exe
並調用where git-credential-manager.exe
cmd.exe
調用where git.exe
C:\\Program Files\\Git\\cmd\\git.exe
C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-credential-manager.exe
where
獲取路徑。我們需要:
/mnt/c/
替換C:\\
\\
翻轉到/
\\\\
轉義空格(和括號,如果有的話)所以...
"C:\\Program Files\\Git\\mingw64\\libexec\\git-core\\git-credential-manager.exe"
變成..."/mnt/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
我上面的腳本有一個功能可以做到這一點
dos_path_to_linux(){
sed -e 's?\\?/?g' -e' s?[cC]:?/mnt/c?' <<<"$1"
}
但是,正如@12345ieee 此后評論的那樣,一個wslpath
實用程序已添加到WSL 版本 17046 中。 值得一試,但我目前無法訪問 Windows 進行驗證。 (請注意,即使在我的鏈接的發行說明中給出了使用說明,但該命令目前似乎不包含使用說明、-h 等)
bash
調用git config --global credential.helper "<converted/path>"
使用 Windows 10 和“WSL”,我創建了一個 ~/.gitconfig 文件,但將 [credential] 部分標簽錯誤地輸入為 [credentials]。 我嘗試運行 git credential fill 然后將其輸出提供給 git credential批准,這可能有效,但我懷疑不是因為它說“用法:git credential [fill|approve|reject]”。 最后,我只是跑了:
$ git config --global credential.helper cache
然后做了一個git pull; 當提示輸入用戶名和密碼時,我像往常一樣輸入它們。 在那之后,它記住了它。 我發現它已將(正確命名的)部分添加到我的 ~/.gitconfig 中:
[credential]
helper = cache
我編輯了它以提供更長的超時時間:
[credential]
helper = cache --timeout=144000
現在這一切似乎都運行良好。
alias git=git.exe
將簡單地使用 windows 中的 git.exe 及其配置
到目前為止,所有答案都過於復雜。 而且 git 文檔並沒有真正的幫助,他們喜歡參考資料很多,所以你需要按照 2-3 個鏈接來獲取你需要的信息!
git.exe
與 WSL 一起使用! 使用 linux git sudo apt install git-all
(我認為它預裝了 Ubuntu)。git 默認支持 2 種方法。 要查看您安裝了哪些方法,請執行以下命令:
git help -a | grep credential
我的結果是:
credential Retrieve and store user credentials
credential-cache Helper to temporarily store passwords in memory
credential-store Helper to store credentials on disk
@selkieTG 在他們的回答中涵蓋了這一點,包括完整性......
git config --global credential.helper "cache --timeout 30000"
將您的密碼/令牌緩存 30,000 秒(8 小時 20 分鍾)
git config --global credential.helper "store"
將純文本密碼/令牌存儲在~/.git-credentials
。
純文本?! 對於 WSL,我完全可以在這里使用純文本。 我輸入憑據以運行我的 Windows 計算機,然后輸入憑據以登錄 WSL2。 我需要隱藏這些嗎? 不是真的,它在我的開發箱上更方便。
如果你真的想使用manager-core
你可以在你的Ubuntu 版本中安裝它。 然后使用它。
我最近剛剛更新到 WSL2,在我的情況下,以下內容不起作用:
"/mnt/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
有效的是以下內容: git config --global credential.helper "/c/Program\\\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"
在我從路徑中刪除/mnt/
,我收到了“未找到”錯誤。
根據我的調查,在干凈的 Windows 啟動后,在 WSL2 中安裝 Windows 驅動器存在問題,更多詳細信息請點擊此處: https://github.com/microsoft/WSL/issues/4122
: https://github.com/microsoft/WSL/issues/4122
在我的情況下,這是最可能的原因.
另一個原因可能是/etc/wsl.conf
中根目錄的錯誤配置
無法在 WSL2 和 Debian 上使用git-credential-manager.exe
進行此操作。 我總是得到remote: Repository not found.
沒有進一步的錯誤。
相反,我對git-credential-manager-core.exe
做了同樣git-credential-manager-core.exe
所以我的配置現在是credential.helper=/mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe
。 這立即奏效,事先在 Windows 上設置了 GitHub 2FA/PAT。
我有以下 git 版本:
下載:(gcmcore-linux_amd64.2.0.567.18224.deb) https://github.com/GitCredentialManager/git-credential-manager/releases/tag/v2.0.567
安裝:
sudo apt install gcmcore -y 或
須藤 dpkg -i <path-to-package.deb> (gcmcore-linux_amd64.2.0.567.18224.deb)
配置:
導出 DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
git-credential-manager-core 配置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.