58

I was following a tutorial from GitHub itself. I am following the one that teaches you to work from Visual Studio Code.

I was trying to push something from Visual Studio Code and after quite some time I get the following error:

remote: No anonymous write access.
fatal: Authentication failed for ....

Now I am pushing something to my personal account. I tried to google (but again I am new to this so I don't fully understand all the terminology) and what I could find are issues with two-factor authentication (but that is off in my case) and Windows credentials (but I checked and I do not have any Git in my Windows credentials).

So I am at a loss. What else I could try or check?

4
  • Are you doing this from the command line / terminal or using VS Code's version control UI? Commented Mar 19, 2020 at 12:36
  • @GinoMempin the UI I would not know exactly how to do it via command line Commented Mar 19, 2020 at 12:52
  • How did you clone the repository on your local machine? Did you use HTTPS or SSH? Commented Mar 20, 2020 at 4:41
  • For those coming from search engines searching for a solution to the Visual Studio Code scandal (the update of Visual Studio Code to version 1.62.2 (October 2021 1.62.0 release, 1.62.2 in November 2021) broke Git push to GitHub - symptom "No anonymous write access"): the Stack Overflow question Fix for "fatal: Authentication failed for" addresses this incident more directly (and is probably the canonical question for it). Commented Nov 18, 2021 at 0:09

9 Answers 9

58

A simpler method is to use personal access tokens at GitHub. This feature can be set up by going to your GitHub account → SettingsDeveloper settingsPersonal access tokensGenerate a personal access token. Make your access control selections, generate, then copy and save your new token. After this, go to your Git project directory and this enter in the terminal:

git remote set-url origin https://[email protected]/your_user/your_project.git

From now on you can easily do git push from the terminal or Visual Studio Code.

Sign up to request clarification or add additional context in comments.

1 Comment

While this doesn't seem like the most ideal or "proper" solution, I can't argue with the results, as it fixed my issue when nothing else was working and I could not figure out the problem. I still don't understand what was going wrong with my setup or why it was failing, but at least now it is working, thank you very much.
13

Visual Studio Code just uses your environment's Git configuration when it commits and pushes to the remote repository. So, you'll have to first make sure that your local environment is set up correctly for Git, before worrying about Visual Studio Code.

First, I recommend going through the First-Time Git Setup from the Git documentation. The most important part there is setting up your Git identity:

git config --global user.name "John Doe"
git config --global user.email [email protected]

Second, I recommend setting up SSH keys on your local machine and on your GitHub profile. GitHub has an entire tutorial on Connecting to GitHub with SSH.

Basically:

  1. Generate a SSH key on your machine (Generating a new SSH key))

    • There's a step there that specifies -C "[email protected]"

    • Make sure that it matches the git user.email that you set as your Git identity

  2. Add that SSH key to your GitHub account, in the SSH and GPG keys section.

You can check that your SSH keys are valid by entering this in the terminal:

ssh -T [email protected]

Output:

Hi ginomempin! You've successfully authenticated, but GitHub does not provide shell access.

Now,

  1. Clone your repository

    • Make sure to select the Clone with SSH option in GitHub

      Enter image description here

  2. In Visual Studio Code, make sure to use that same [email protected]:..... URL

    Enter image description here

I do not have any Git in my Windows credentials

You can choose to disable that entirely, as I find that the Windows Credential Manager can cause problems, and using SSH is more "stable". See How do I disable Git Credential Manager for Windows?.

9 Comments

I followed all your steps. Nice and clear by the way thank you. When I tried to check the ssh key I got the following: Warning: Permanently added 'github.com.... But then I got the same message as you. So I thought it was fine. However in the second step of vs code I get the following error: Cloning into 'd:\Users\hillebr\Documents\2 - Test programma's\github-slideshow'... Warning: Permanently added the RSA host key for IP address ....... to the list of known hosts. [email protected]: Permission denied (publickey). fatal: Could not read from remote repository.
What does ssh -T [email protected] give you? The warning about "Permanently added 'github.com' to the list of known hosts" is normal and expected. It's just telling you that "Hey, I'm going to use your SSH key on this machine to access Github".
Looks fine: You've successfully authenticated, but GitHub does not provide shell access
Hmm. Can you try going over the Github docs on Troubleshooting SSH > Error: Permission denied (publickey)? Usually, it's an incorrect git user configuration.
If you already clone using https, you can switch the remote protocol via: git remote set-url origin [email protected]:USERNAME/REPO.git
|
11

Yahooo! Finally, an issue is resolved

This is only for those who are facing this issue from the last update of Visual Studio Code (2021-11-15 or around).

The issue on GitHub Community #LINK

There isn't any need to downgrade Visual Studio Code or the Git version. Basically, that is what I understood from the fix that worked for me. I think it's a sort of conflict between GitHub and Git authentication.

So there are a few steps you can try and hopefully it would be fixed for you too.

Open your Settings in Visual Studio Code.

  1. Open settings from the left bottom corner (Settings icon) or press Ctrl + ,

  2. type "Authentication" in the search option. It will show something like this:

    Enter image description here

  3. You need to uncheck Git: Terminal Authentication (for example)

    Enter image description here

  4. Only GitHub: GitHub Authentication should be checked.

Now you need to close the opened terminal (if any). Open your new terminal and try with Git commands.

Enter image description here

On my end, everything is working fine.

5 Comments

Same issue with me after the latest update. But this didn't work for me
@rajabraza which os are you using? and VS Code version? can you confirm, make sure you closed the terminal and opened a new one.
Ubuntu 20.04. Yes, I even restarted the workstation as well. Also, I have upgraded the VSCode to version 1.62.3 but nothing helped.
Version: 1.62.3 Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247 Date: 2021-11-17T08:00:36.721Z Electron: 13.5.2 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.13.0-21-generic snap its working on mine, (versions are same as yours).
This solution worked for me. In addition, I also reloaded my VS code.
5

After setting up the SSH key, you need to type this in your IDE (I'm using Visual Studio Code)

git remote -v

This will show you your current remote branch URL, but you can no longer use that.

To update it, type this in your console

git remote set-url origin [email protected]:YOURUSERNAME/reponame.git

Now try to push or make any changes

NOTE: From my perspective I think you'll have to perform this operation for all your existing (old) repositories too.

1 Comment

This worked for me. Output of git remote -v gave me origin https://github.com/*my_github_username*/*github_reponame*.git (fetch) ... . I used git remote set-url origin [email protected]:YOURUSERNAME/reponame.git (I copied the corresponding part ([email protected]:YOURUSERNAME/reponame.git) directly from my github repo page in "Code" section/tab > then clicking the big green "Code" button with a dropdown menu > then selecting "SSH")
2

Try to go through the terminal with sudo git push. If you have two-factor verification, use the token instead of the password like this:

Username for 'https://github.com': <username>

Password for 'https://[email protected]': <token>

1 Comment

Is there a difference between two-factor verification and two-factor authentication?
2

You need to go back to the old version of Visual Studio Code and everything will be fine and all problems will be solved. It seems that the problem is in the latest version of Visual Studio Code and I hope it will be fixed. I am using Linux, an Ubuntu distribution.

September 2021 (version 1.61)

Enter image description here

Comments

0

Delete your working branches after merging successfully and then:

git status
git push

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

For those still struggling, Windows credentials was the culprit in my situation:

Original answer

All my local/global settings were set, reset, deleted, etc., etc., but nothing worked.

I deleted everything Git-related in Windows Credential Manager, and it was fixed.

Comments

0

What I have learned is that: You cloned the repository into an SSH terminal in Visual Studio Code. The first thing you could have done is to use a Git Bash terminal. It usually has the sign ">" as against the Bash terminal, which has a cube-like sign.

So before you clone a repository make sure you are using a Git Bash terminal, hence, why the problem. Here is what I did. So since you used bash we have to play with "ssh".

First step, write this command in the repository you cloned

git config --global user.name "username in github"
git config --global user.email "email used in gihub"

Second Step

Follow this documentation patiently

When you get to this step below in the document, continue below;

Step 2

Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

ssh-add ~/.ssh/id_ed25519

Instead of typing the command "ssh-add ~/.ssh/id_ed25519", use this: ssh-add,

It will prompt you to enter paraphrase or something. Type it.

Then make sure you have added the SSH key successfully by running this code:

ls -al ~/.ssh

Try and cd to the directory of ssh.

You should see something like this:

-rw--- 1 barry barry 465 Nov 1 07:47 id_ed23333
-rw--  1 jospeh jose 115 Nov 1 09:47 id_ed23333.pub

Try and run this command:

cat id_ed23333.pub

It will give you your SSH key. Copy it and go to your GitHub account. After this, go to your repository, click on "code". You should see http /ssh. Click on "ssh'. It should show you if you need to add an SSH key. Click on the Add key. Name the key anything you want and paste the key you copied then add key.

Go back to Visual Studio Code and rerun the usually code.

git add .
git commit -m "message"
git push

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.