Git Permission Denied Error Pushing Files via Windows CMD
If you're working with Git on Windows CMD and encountering a "Permission denied (publickey)" error when trying to push a folder repository, this article is for you. We'll cover the key concepts and context around this issue and provide a detailed guide on how to resolve it.
Understanding the Error
The "Permission denied (publickey)" error is a common issue when using Git on Windows CMD. This error occurs when Git is unable to authenticate your SSH key, which is necessary for accessing your GitHub repository. To resolve this issue, you'll need to generate a new SSH key and add it to your GitHub account.
Generating a New SSH Key
To generate a new SSH key, follow these steps:
- Open the Command Prompt on your Windows machine.
- Type the following command and press Enter:
ssh-keygen -t rsa -b 4096 -C "[email protected]" - Press Enter when prompted to "Enter a file in which to save the key." This will save the key to the default location.
- Enter a passphrase for your key when prompted.
This will generate a new SSH key and save it to your system. The next step is to add this key to your GitHub account.
Adding the SSH Key to Your GitHub Account
To add the SSH key to your GitHub account, follow these steps:
- Copy the contents of your new SSH key by typing the following command and pressing Enter:
clip < ~/.ssh/id\_rsa.pub - Log in to your GitHub account and navigate to your account settings.
- Click on "SSH and GPG keys" in the left-hand menu.
- Click the "New SSH key" button.
- Paste the contents of your SSH key into the "Key" field.
- Click the "Add SSH key" button.
This will add the new SSH key to your GitHub account, allowing you to authenticate and push your repository.
Testing Your SSH Key
To test your SSH key and ensure that it's working properly, follow these steps:
- Open the Command Prompt on your Windows machine.
- Type the following command and press Enter:
ssh -T [email protected] - If the SSH key is working properly, you should see a message that says "Hi [your GitHub username]! You've successfully authenticated, but GitHub does not provide shell access."
The "Permission denied (publickey)" error is a common issue when using Git on Windows CMD. By generating a new SSH key and adding it to your GitHub account, you can resolve this issue and push your repository without any issues. Remember to test your SSH key to ensure that it's working properly.