# Fix Git Credential Helper Not Storing Passwords in WSL2
You configure Git to use a credential helper in WSL2, but every git push still asks for your username and password:
git config --global credential.helper cache
# Or
git config --global credential.helper storeThe credentials are either not stored, stored in the wrong location, or cannot be accessed from WSL2's Linux environment.
Step 1: Check Current Credential Helper
git config --global credential.helper
git config --local credential.helper
git config credential.helperThe output shows the active credential helper. If nothing is returned, no helper is configured.
Step 2: Use Windows Credential Manager From WSL2
The most reliable approach is to use the Windows Git credential helper from within WSL2:
# Configure Git in WSL2 to use the Windows credential manager
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"Or for the newer Git Credential Manager (GCM):
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/bin/git-credential-manager.exe"This allows WSL2 Git to store credentials in the Windows Credential Manager, which persists across WSL2 restarts.
Step 3: Enable GCM in WSL2
If you have Git for Windows installed, GCM can be used directly from WSL2:
```bash # Install GCM core in WSL2 sudo apt update sudo apt install gpg
# Download and install GCM wget https://github.com/GitCredentialManager/git-credential-manager/releases/latest/download/gcm-linux_amd64.deb sudo dpkg -i gcm-linux_amd64.deb
# Configure git config --global credential.helper manager ```
Then authenticate:
git credential-manager configure
git credential-manager authenticate https://github.comThis opens a browser for OAuth authentication. After completing the flow, credentials are stored securely.
Step 4: Use git-credential-store (Plain Text)
For a simple solution that stores credentials in plain text (less secure):
git config --global credential.helper storeThis stores credentials in ~/.git-credentials. The next git push will ask for credentials one more time, then store them.
cat ~/.git-credentials
# https://username:password@github.comWarning: This stores passwords in plain text. Only use this on personal machines.
Step 5: Use git-credential-cache (In-Memory)
For temporary credential storage (cleared on WSL2 restart):
git config --global credential.helper 'cache --timeout=3600'This caches credentials in memory for 1 hour (3600 seconds). After WSL2 restarts, the cache is lost and you must re-authenticate.
Step 6: SSH Instead of HTTPS
The most robust solution for WSL2 is to use SSH authentication instead of HTTPS with credential helpers:
```bash # Generate SSH key in WSL2 ssh-keygen -t ed25519 -C "your-email@example.com"
# Start SSH agent eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519
# Add public key to GitHub cat ~/.ssh/id_ed25519.pub # Copy and add to GitHub > Settings > SSH Keys
# Change remote to SSH git remote set-url origin git@github.com:user/repo.git
# Test ssh -T git@github.com ```
SSH keys persist across WSL2 restarts and do not require credential helpers.
Step 7: WSL2 Interop Configuration
For the Windows credential helper to work, WSL2 interop must be enabled:
# Check interop
cat /proc/sys/fs/binfmt_misc/WSLInteropIf interop is disabled, enable it in /etc/wsl.conf:
[interop]
enabled=true
appendWindowsPath=trueThen restart WSL2:
wsl --shutdown
wslStep 8: Troubleshooting GCM in WSL2
If GCM does not work:
```bash # Enable debug logging git config --global credential.helper 'manager --debug'
# Try a push to see debug output git push ```
Check the GCM log:
cat ~/.git-credential-manager/logs/*.logCommon issues:
- Browser not available: WSL2 cannot open a browser for OAuth. Use GCM_INTERACTIVE=never and provide a PAT:
``bash
GCM_INTERACTIVE=never git push
- **Keyring not available**: Install a keyring package:
bash
sudo apt install libsecret-1-0 gnome-keyring
Best Practice for WSL2
The recommended setup for WSL2 development:
- 1.Use SSH keys for GitHub/GitLab authentication (most reliable)
- 2.If HTTPS is required, use GCM with browser-based OAuth
- 3.As a fallback, use
credential.helper storewith plain-text storage - 4.Never use
credential.helper cacheas the primary solution (lost on WSL2 restart)