Reputation: 611
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.
Upvotes: 1
Views: 2258
Reputation: 611
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 name vscodevscode.github-authentication
.
Indirectly via git-credential-osxkeychain
and a personal access token that is stored in the Keychain with the name github.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.
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
Always Allow
on the request that asks to ...access key "github.com"...
Allow
on the request that asks to ...use your confidential information stored in "github.com"
.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 Homebrew
At least for me this solution works for pushing via VS Code GUI, VS Code integrated terminal and OS terminal.
Upvotes: 3
Reputation: 1323363
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.
Upvotes: 0