How can I force VS Code to ask for my macOS Keychain password before each push to GitHub?
VS Code never asked for my GitHub password (via Keychain) until I pushed to GitHub and it asked before each push again.
This was working until a few hours ago when I had some issues and revoked my access and VS Code requested a new token.
Now VS Code does not ask at all for a password. Even when I remove VS Code from the Keychain whitelist, it asks for my password at program start only once and then not again, even not for pushes.
I want VS Code to request my GitHub token before each push from Keychain again.
CodePudding user response:
After comparing my current macOS login Keychain with one from a Backup where everything was still working as I wanted, I found a solution:
There seem to be at least two ways of how VS Code accesses the Keychain:
Directly via
OAuth
. This is used when VS Code automatically requests an access token via the GitHub website. It stores the token in the Keychain with the namevscodevscode.github-authentication
.Indirectly via
git-credential-osxkeychain
and a personal access token that is stored in the Keychain with the namegithub.com
.
VS Code seems to decide automatically which way it uses depending on which keys it finds in the macOS Keychain.
I have not found a way how to force VS Code to ask for the Keychain password on each push when using OAuth
, but it is working via git-credential-osxkeychain
now.
Solution
Request a personal access token via GitHub / Settings / Developer settings / Personal access tokens
Retreive your GitHub ID via:
https://api.github.com/users/<your user name>
Open
Keychain Access
and create a new password item:
Keychain Item Name:https://github.com
Account Name:<your GitHub ID>
Password:<your personal access token>
Notes:
If VS Code asks for your Keychain password multiple times, try a push via command line
- click on
Always Allow
on the request that asks to...access key "github.com"...
- click on
Allow
on the request that asks to...use your confidential information stored in "github.com"
.
- click on
This is a complete "try and error" solution, I have not found much information about that. It would be great if someone could explain what is actually going on here. I have also not found any official information about setting up VS Code via
git-credential-osxkeychain
.I guess
git
needs to be installed to make that work. I installed it via HomebrewAt least for me this solution works for pushing via VS Code GUI, VS Code integrated terminal and OS terminal.
CodePudding user response:
Check your git config --global credential.helper
: it references the program in charge of caching your credentials.
A git config --global --unset credential.helper
would remove it, forcing Git to always ask for your credentials.