50

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user180146
  • 895
  • 2
  • 9
  • 18
  • Are you doing this from the command line / terminal or using VS Code's version control UI? – Gino Mempin Mar 19 '20 at 12:36
  • @GinoMempin the UI I would not know exactly how to do it via command line – user180146 Mar 19 '20 at 12:52
  • How did you clone the repository on your local machine? Did you use HTTPS or SSH? – Gino Mempin Mar 20 '20 at 04: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"](https://stackoverflow.com/questions/69979522/)* addresses this incident more directly (and is probably the canonical question for it). – Peter Mortensen Nov 18 '21 at 00:09

7 Answers7

46

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://YOUR_TOKEN_HERE@github.com/your_user/your_project.git

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

sequence
  • 744
  • 1
  • 8
  • 16
  • 2
    Thanks for updating your answer. It works! – McGrew Nov 19 '21 at 21:31
  • 2
    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. – ForeverZer0 Apr 25 '22 at 08:07
11

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

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

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

2nd, 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 "your_email@example.com"
    • 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 git@github.com
Hi ginomempin! You've successfully authenticated, but GitHub does not provide shell access.

Now,

  1. Clone your repo
    • Make sure to select the Clone with SSH option in GitHub enter image description here
  2. In VS Code, make sure to use that same git@github.com:..... 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 credentials manager can cause problems, and using SSH is more "stable". See How do I disable Git Credential Manager for Windows?.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • 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. git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.``` – user180146 Mar 20 '20 at 08:40
  • What does `ssh -T git@github.com` 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". – Gino Mempin Mar 21 '20 at 13:50
  • Looks fine: ```You've successfully authenticated, but GitHub does not provide shell access``` – user180146 Mar 23 '20 at 07:57
  • Hmm. Can you try going over the Github docs on [Troubleshooting SSH > Error: Permission denied (publickey)](https://help.github.com/en/github/authenticating-to-github/error-permission-denied-publickey)? Usually, it's an incorrect git user configuration. – Gino Mempin Mar 23 '20 at 11:25
  • Going through this it looked like I did not have an ssh key so I followed the steps to create one. If I afterwards try to add it using ```ssh-add ~/.ssh/id_rsa``` I get ```Could not open a connection to your authentication agent``` It could very well be that I forgot this step last time, so I did not notice then. – user180146 Mar 23 '20 at 14:40
  • 2
    If you already clone using https, you can switch the remote protocol via: `git remote set-url origin git@github.com:USERNAME/REPO.git` – Moop Nov 13 '21 at 19:22
  • I am able to connect sshkey to github and also tested it via `ssh -T git@github.com`, but still I am getting the same error. Do I need to copy the whole thing to SSH key content of github account like key+email or only keyy? – MagnusEffect Nov 14 '21 at 13:16
  • @MohitMaroliyaB17CS036 You need to copy the entire thing, the entire contents of your public key. See the Github help page I linked to in my answer: https://help.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account. There is a sample command there how to copy the key for Windows, Mac, and Linux. – Gino Mempin Nov 14 '21 at 23:32
9

Yahooo! Finally, an Issue resolved

This is only for those who are facing this issue from the last update of VS Code. (NOV 15, 2021 or around)

The issue on Github Community #LINK

No need to downgrade VS Code, or git version. basically what I understood from the fix that worked for me. 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 VS 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. (e.g) 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. hope this works for you too. :slight_smile:

Jahanzeb Nawaz
  • 1,128
  • 12
  • 11
  • Same issue with me after the latest update. But this didn't work for me – rajabraza Nov 21 '21 at 17:37
  • @rajabraza which os are you using? and VS Code version? can you confirm, make sure you closed the terminal and opened a new one. – Jahanzeb Nawaz Nov 21 '21 at 19:56
  • 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. – rajabraza Nov 22 '21 at 09:41
  • 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). – Jahanzeb Nawaz Nov 22 '21 at 19:03
  • This solution worked for me. In addition, I also reloaded my VS code. – joseph chikeme Apr 27 '23 at 23:12
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 git@github.com: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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Opeyemi Noah
  • 136
  • 1
  • 11
  • 2
    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 git@github.com:YOURUSERNAME/reponame.git` (I copied the corresponding part (`git@github.com: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") – PurpleMongrel Nov 23 '21 at 03:06
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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fares
  • 53
  • 5
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://username@github.com': <token>

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Artrinias
  • 21
  • 2
  • Is there a difference between two-factor verification and [two-factor authentication](https://en.wikipedia.org/wiki/Two-factor_authentication)? – Peter Mortensen Nov 16 '21 at 16:43
0

What I have learn is that, You cloned the repository into an ssh terminal in vs-code. The first thing you could have done is to use gitbash terminal, it usually has this sign ">" as against the bash terminal which has a cube-like sign.

So before you clone a repository make sure you are using a gitbash 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 docs 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 this 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 add key, name the key anything you want and paste the key you copied then add key.

Go back to vscode and rerun the usually code.

git add .
git commit -m "message"
git push
Dharman
  • 30,962
  • 25
  • 85
  • 135
derek
  • 21
  • 7