Is there a way to restore Github and Bitbucket 2FA without recovery codes or backup phone number? - github

My android device broke and I lost access to Github and Bitbucket 2 factor authentication codes.
Unfortunately I didn't save the recovery codes or set up a backup phone number to receive codes by SMS, and I'm not signed in to Github and Bitbucket on any computer.
Is there another way to gain access to my Github and Bitbucket account?

Luckily for me, there is a way to do this if you assigned a SSH key to your account.
What you need to do is to run this command on the computer where you have the SSH key:
ssh -T git#github.com verify
And send the output to Github support. With that output they are able to disable your 2fa and allowing you to login just with your password.
The output should look like this:
Please provide the following verification token to GitHub Support.
002de4e72d08f47b0b828bab0224dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf6174ce54ab0040aa7075626c69635f6b6579ce008cacf9
If you are reading this it's probably too late for that advice but don't be stupid like I was. Save the recovery codes or set up a phone number!

This works only if you have access to your bitbucket and github via SSH.
Even for #achiash 's answer.
For github as #achiash mentioned you can use
ssh -T git#github.com verify
This will print the verification code on your screen.
For bitbucket you can use
ssh git#bitbucket.org recovery_codes
This will ask you for password. Enter the password and it will print your recover codes.

Related

GitKraken asking for GitHub credentials despite ssh key upload

In preferences→Integrations→GitHub I uploaded a GitKraken SSH key to GitHub. However, after pressing “Pull” GitKraken still asks me to log in, which does not work. The login dialog pops up again and again.
Any idea?
Looks like a closed port at our firewall was the problem. I wonder if GitKraken can’t tell the difference between that and a failed authentication at GitHub. And if so, maybe it should first test the SSH port with other means, e.g. authenticating somewhere it knows it can.

Github 2FA won't let me push to branch

Just added 2FA for Github but now when I go to push changes from the terminal to a branch and I try to authenticate myself with username + password I get rejected because there's nowhere to input my 2FA code...I know my username and password are correct because I can login to the site (with 2FA code). Terminal doesn't provide a space to input that code. How are others working around this?
You'll need a personal access token or SSH key.
The details are here: Accessing GitHub using two-factor authentication - Using two-factor authentication with the command line

How do I sign in to GitHub from command line after password access is removed?

GitHub is retiring password based authentication for command line tools: https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/
Normally I work in some server, git clone https://...., enter my username and password and get the code that I have to deploy.
What am I supposed to do now? Do I create a token, write it down on a piece of paper, take it with me and retype it into a terminal? Seems a bit too convoluted for just getting some code. Is there some other "intended" workflow?
There are a few options:
You can create a personal access token in your github settings and use that instead of your account password.
you can use SSH to connect
you can rely on the Git Credential Manager Core which will perform an OAuth check either by popping up a UI or giving you an url to paste into a browser.
some hardware tokens will enable you to perform authentication.

Why does github keep asking me for repo credentials?

We recently moved our github from one account owner to another, and now all of the sudden when I do a git pull or any git command on the remote repo, it asks me for github username and password.
My git-config says:
[github]
user = kamilski81
token = *********
Any idea how I can stop it asking me for credentials and remember everything, does the new owner have to setup my ssh keys or something of that sort?
Following this article sorted it out for me:
https://help.github.com/articles/why-is-git-always-asking-for-my-password
git remote set-url origin git#github.com:user/repo.git
The github username and token in the gitconfig is only used for interactions with the GitHub API (for instance the hub gem and the github tool).
If you are pushing and pulling from a GitHub repository over https, then you need to specify your credentials every time, or hook into a password manager to remember the credentials for you. How to do this depends on your platform.
The easiest thing to do is to go to your github account and submit your SSH public key to your account, and then switch your github remote to push/pull over ssh instead of https.
[edit] After re-reading the question I noticed that you mentioned it was previously a GitHub repo that was just moved from one owner to another. If that's the case, and you ARE able to push and pull by specifying your credentials, it sounds to me to be one of two scenarios:
The previous remote used ssh, and GitHub has your SSH key; but when the owner changed and you updated the remote, you updated it to go over https.
The previous remote used https, but you had a password manager setup correctly to deal with your credentials, which no longer works.
After doing "remote -v"....the issue was that my remote was using an "https" remote rather than "git" remote. Changing the remote to use git rather than https solved everything.
If you execute only once git pull and Git client still asking you the credential without do the git pull for you, the problem should be because your credential is incorrect or not setup yet.
but if you get the dialog ask for credential one for each operation, it mean that your credential isn't remembered. To do that, you may use Pageant to store your SSH private key, so, everytime you do something, it will retrieve your credential from Pageant instead to asking you.

What to do about "PTY allocation request failed on channel 0"

I can't see to wrap my head creating an ssh key for GitHub. I had it working quite awhile back but I can't figure out what has changed. I've since removed the previous SSH keys from my GitHub account. After following the instructions several times for generating an SSH key (http://help.github.com/mac-key-setup) and testing "ssh git#github.com" I get the following;
PTY allocation request failed on
channel 0 ERROR: Hi...successfully
authenticated...GitHub does not
provide shell access...Connection to
github.com closed.
I reviewed the troubleshooting guide and noticed that my ssh directory didn't have a config file. After creating it I'm unsure of what or how to enter the local path on the IdentityFile line. I'm not even sure whether this is necessary in my case?
If your github authentication
information is different from your
machine account information, you’ll
need to modify your ssh configuration
file.
Create or open the file at
~/.ssh/config Add the following lines:
Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile [local path to private key half of github public key you provided]
You may also need to update the
permissions on your .ssh folder and
its contents. The SSH application will
ignore secret files that are too
permissive.
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/*
I also ran ssh -v git#github.com the results of which can be seen here http://gist.github.com/607283 nothing different from what I can tell.
Any idea what I'm doing wrong?
As described in the comments on the question, the “PTY allocation request failed” is a red herring with respect to GitHub authentication (it is the result of trying to interactively login to GitHub when the only SSH service they offer is non-interactive Git-over-SSH; the authentication is working, they just do not provide interactive, “shell” service).
The person who asked the question wrote this in a comment:
I guess the related problem is that when I try to create a new repository and "git push origin master" I return the following "Error: Permission to myemail#address.com/myapp denied to myusername. Fatal: the remote end hung up unexpectedly"
This seems more likely to be the actual problem. This seems to indicate that the remote named origin not configured to correctly point to a GitHub repository.
Check the output of git remote show -n origin. Probably the “Fetch URL” and the “Push URL” are the same. They should both look like this:
git#github.com:git-user-name/repository-name
When logging into GitHub on the web you can use either your account’s username or its associated email address. When pushing to repositories (or fetching from private repositories) you have to use your actual username (an email address will not work). It looks you are using your email address in there instead of just your GitHub username. To fix this, reconfigure the remote’s URL:
git remote set-url origin git#github.com:github-username/repository-name
Your username is displayed in many places on the GitHub web pages once you are logged in. The easiest place to find it is between your gravatar and the “Dashboard” link on the page header (you will see a silhouette icon if you do not have a gravatar configured). That same location links to your public profile page; this page’s URL should also end in your username.