Hello. I have been completely flummoxed by this move from app passwords to API tokens. It seems I am not alone in that.
have been using only a tiny subset of git capabilities in my single-user workflow, but it's enough for me. So I"m a long-time but still inexperienced user.
I use git via command line on Linux Mint. I have my credentials stored. (Yes, I know, but I am the only person with physical access to my computers.) So to push and pull (really my only actions) I simply do::
git pull
or
git push
when in my project directory.
How do I switch that to use API tokens? Could someone please share the sequence of commands to:
forget my current credentials
store my token-based credentials
pull and push
Thank you very much.
Why don't you use an ssh key ?
steps
ssh-keygen
add generated pub key to your bitbucket account https://bitbucket.org/account/settings/ssh-keys/
use git@ urls instead of http urls for git clone
change existing remote urls with git remote command
see also, but I don't see the need for the ssh agent mentioned there
https://support.atlassian.com/bitbucket-cloud/docs/set-up-personal-ssh-keys-on-linux/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @ryancw
Your credential.helper store will cache the new token automatically. Ensure it has both read:repository:bitbucket and write:repository:bitbucket scopes, then clear the old credentials by running:
printf "protocol=https\nhost=bitbucket.org\n\n" | git credential reject
Next, run git pull, enter your case-sensitive username, and paste the token as the password to save it. If that fails, you can force Atlassian's token auth by running git remote set-url origin https://x-bitbucket-api-token-auth@bitbucket.org/<workspace>/<repository>.git and pulling again, just don't put the actual token string in the URL.
Best,
Arek 🤠
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Arkadiusz Wroblewski thank you so much! That was simple, and so far it seems to have worked.
rcw@rcw-lm203c:~/DATA/BookIdeas$ printf "protocol=https\nhost=bitbucket.org\n\n" | git credential reject
rcw@rcw-lm203c:~/DATA/BookIdeas$ git push
Password for 'https://ryancw@bitbucket.org': #### I put in my API token ####
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 967 bytes | 967.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://bitbucket.org/ryancw/bookideas.git
a501f4a..4600866 master -> master
rcw@rcw-lm203c:~/DATA/BookIdeas$ cd ../etm
rcw@rcw-lm203c:~/DATA/etm$ git status -uno
On branch master
Your branch is up to date with 'origin/master'.
I wasn't sure if I needed to run your one-liner afresh in every directory where I have a git-monitored project. I tried it in a different one, and git did not ask me to re-enter my password/token. So maybe not? Maybe entering it once changes the behavior globally?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Exactly you only need to do this once.🤠
Because credential.helper store saves credentials globally in ~/.git-credentials, your new token automatically applies to all HTTPS Bitbucket repos using that username. You'll only be prompted again if the token expires, you switch to SSH, or you change usernames.
Just keep in mind that store saves tokens in plaintext on disk, a Linux keyring or Git Credential Manager is safer if you ever want to upgrade.
But you was using it before so I assume that's Trade-off you accepting.
Glad it's working! 🙂
Best,
Arek 🤠
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Arkadiusz Wroblewski Fair point about the plain text. I'm not too worried, but if I *was* to tighten up my security, how do I make git stop storing my password/token, and to ask me for it every time I push or pull? That would not be a big burden, since I have it stored in linux pass, and can just do
pass -c pass/path/to/my/token
and enter my key's passphrase when asked
to copy that long token string to the clipboard for 45 seconds.
Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.