简体   繁体   中英

github, sourcetree getting unauthorized error

im new to github and im using sourcetree for my git gui, ive been using it for a few days, but now lately im getting an error that says

remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/Nosthertus/nodejs_Chat.git/'

also when i tried to make another registration to github returns with error

authorization failed

maybe its because i made a two-factor security, i thought on making a shh-key with github, but does not fix the problem, there has to be a way to make my gui connect to my github account without the login access, how do i fix this?

If your password recently changed, select the repository, go to Tools --> options, go to Authentication tab and delete the stored password. This will make the system request a new password when you next try to connect.

On OSX: go to SourceTree --> Preferences --> Network and delete the default username there.

its because i made a two-factor security

Following the Heartbleed bug , GitHub has reset all browser sessions that were active prior to the vulnerability being addressed on our servers.

Check if your PAT (Personnal Access token) is still valid in the Applications section of your GitHub Account .

Note that ssh keys have no effect on an https url like https://github.com/Nosthertus/nodejs_Chat.git

Would you need to use your ssh key, you should at least change the origin url:

git remote set-url origin git@github.com:Nosthertus/nodejs_Chat.git

我正在使用个人访问令牌(GitHub - >设置 - >个人访问令牌),我需要重新生成令牌,然后从SourceTree中删除用户名(SourceTree - >首选项 - >网络 - >删除)然后拉,你将成为提示输入用户名和密码使用您生成的令牌

To work with GitHub's two-factor authentication in SourceTree you can simply use your access token instead of your password. The steps to do this are as follows:

  1. Go to your Personal Access Tokens settings in GitHub.
  2. Click on the Generate new token button.
  3. Name the token something descriptive.
  4. Select which scopes you wish to grant this token.
  5. Click the Generate token button.
  6. Copy the token and use it as a password in your hosted repositories.

Source

I am using 2FA and I was able to resolve authentication issues by creating an API key as described in the linked document:

https://confluence.atlassian.com/sourcetreekb/two-factor-authentication-2fa-with-github-in-sourcetree-402033499.html

Note: after generating the key, copy it and replace your password with the API key in SourceTree (Tools/Options/Authentication tab --> select item in Saved Passwords and click edit...)

I hope this helps.

SOURCE TREE

Tools > Options > Authentication > Edit (Edit Password)

Make sure that your credentials are OK (please check before in the GitHub website), then, in my case the answer was the following.

1) Delete the "psswd" file without opening Sourcetree:

C:\\Users\\USER\\AppData\\Local\\Atlassian\\SourceTree\\passwd

2) After doing that, try to re-enter the application and specify your credentials again.

3) If the previous steps doesn't work, in my case, it was using an incorrect username, so you can edit the "userhosts" file located in the same folder and change to the proper username that you're using:

C:\\Users\\USER\\AppData\\Local\\Atlassian\\SourceTree\\userhosts

By doing this, I was able to push again. Hope it helps!

In addition to setting up the Personal Access Token as Ferie states above, this may be helpful (it's how I finally got it working)

  • I made sure had the latest version of Sourcetree
  • I upgraded to the latest version of and used System Git (Tools -> Options -> Git)
  • Upgraded to the latest Git Credential Manager for Windows (this was via an installer I downloaded and double-clicked, very easy)
  • Ensured I was using OAuth for my GitHub account stored in Tools -> Options -> Authentication
  • Made sure I checked off the box "Allow Sourcetree to manage my credentials using the Git Credential Manager" (this was important!!) on Tools -> Options -> Git
  • Then when I triggered the GitHub dialog (via pushing a new branch, just an example), I logged in there (this is where it used to fail).
  • I next got the 2 factor auth dialog, and the code was sent to my phone as expected. I was able to enter the code from my phone into this dialog.
  1. In GitHub, on the top-right corner, click on the profile icon and select Settings .

在此处输入图片说明

  1. From the left-side menu, towards the bottom, select Developer Settings .

在此处输入图片说明

  1. Select the Personal access tokens option.

在此处输入图片说明

  1. now finally click on the Generate New Token button/link.

在此处输入图片说明

This will prompt you to enter your password. After entering your password, you will see a page to add new token.

在此处输入图片说明

1. Depending on the requirement, you can set an expiration for your token, or you can set "No expiration" from the dropdown.
2. For scopes, agin, upon your requirement, check-mark the necessary ones.
3. Finally hit `Generate token`.

This will generate a token. Keep a copy of the token.

1. In source tree, from the top-right, select `Settings`. 
2. In the pop-up, select remote to add your remote path for repository.
3. Copy the repository path(the .git path) from GitHub into the `URL/ path`, but now you need to add the access-token like following-

在此处输入图片说明

if the repository path is https://github.com/username/repository_name.git , you need to add the access token in-between https:// and github.com/username/repository.git with @ like-

https://access_token@github.com/username/repository.git

hit ok and you are good to go now.

If all above is not work, you can try (it works for me)

  • In command, open: %LOCALAPPDATA%\Atlassian\SourceTree\passwd
  • Delete your usename and password, then try to fetch,push...in source tree, it will ask you input usename password again
  • Input new username/password. Sometime, the password is a token, (eg when you working with azure devopt, depend to your setting you can get the token to input to password field在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM