- Preface
- How to open terminal
- SSH keypair generating
- Port 22
- Permission denied
- Permission denied (publickey)
- Fatal: Authentication failed
Hello, silly boy/girl. If you're reading this, it means you've encountered issues with Git, and Mr. Migranov has redirected your problem-solving request to this document.
Good for you I know how to resolve your problem. First find your issue on the navigation section and then follow described instructions.
There is no terminal in Windows, but there is a console. But we will call terminal anyway. In order to open a terminal window in Windows follow the step below:
- Press
Win+R
, typecmd
and pressEnter
.
To open a terminal window in a Linux distribution follow the instruction:
-
Press
Ctrl+Alt+T
orShift+Ctrl+T
. -
If it doesn't work, then try to find a terminal app via a search engine.
-
If you don't understand the previous step, or it doesn't work, then use
Ctrl+Alt+F2
(or F3-F6). It will open the console line interface. To get back to GUI useCtrl+Alt+F1
(of F7).
If you don't have an SSH keypair yet, you need to generate one to authenticate with remote repositories over SSH.
-
Generate the SSH keypair
Run the following command in a terminal window to generate a new SSH keypair:ssh-keygen -t rsa -b 4096
-t rsa
specifies the type of key (RSA).-b 4096
sets the key length to 4096 bits for better security.
-
Choose a location for the key
You'll be prompted to specify a file to save the key. PressEnter
to accept the default location (~/.ssh/id_rsa
). -
Set a passphrase (optional)
You'll be asked to enter a passphrase for your key. This adds an extra layer of security. You can pressEnter
to skip this, but using a passphrase is recommended. -
Add the SSH key to the agent
Once your key is generated, add it to your SSH agent:eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa
Replace
id_rsa
with the name of your private key file, if it's different. -
Add your public key to GitHub
Copy the public key to your clipboard:cat ~/.ssh/id_rsa.pub
Then go to GitHub's
Settings
>SSH and GPG keys
, clickNew SSH key
, and paste your key. -
Test your connection
Verify that everything is working by running:ssh -T git@github.com
You should see a success message confirming the connection.
This error usually occurs due to an incorrect or malformed remote repository URL in your Git configuration.
-
Check arguments correctness
Ensure arguments you specified for your git command are proper. -
Check your remote URL
Run the following command in your terminal to check the current remote URL:git remote -v
Ensure that the URL is correct. If not, update it by running:
git remote set-url origin CORRECT_URL
Replace
CORRECT_URL
with the correct repository URL (either HTTPS or SSH). -
Verify internet connection
Ensure you have an active internet connection, as Git might return the error if the network is down. -
Check repository access
If you're using HTTPS, ensure you have the correct credentials to access the repository. For SSH, make sure your SSH keys are properly configured and added to your GitHub. -
Retry your git command
After fixing the URL or credentials, retry the Git command that caused the error.
If you're facing a "403 Forbidden" error while trying to push or pull from a Git repository, it's usually due to incorrect credentials or access issues.
-
Resign oneself
If you wanna mess up somebody's repo, but you ain't got collaborator access, it ain't gonna work, boy/girl. -
Check your repository access
Ensure that you have the correct permissions for the repository. If it's private, confirm that you are either the owner or have been granted collaborator access. -
Verify your remote URL
Run the following command to check the remote URL of the repository:git remote -v
If it shows an HTTPS URL (e.g., https://github.com/...), it's recommended to switch to SSH for better security. To change the remote URL to SSH, run:
git remote set-url origin git@github.com:USERNAME/REPO.git
Replace USERNAME and REPO with your actual GitHub username and repository name.
-
Set up your SSH key
Make sure your SSH key is added to your GitHub account. Refer to the steps in the section above to generate and add an SSH key if you haven't done so. -
Clear cached credentials (if using HTTPS)
If you're using HTTPS and previously entered wrong credentials, clear the cached credentials:git credential-cache exit
Then try to push or pull again. Git will prompt you for credentials, where you can enter the correct ones.
-
Retry your Git command
Once you've verified access and set up your credentials, run the Git command again to see if the issue is resolved.
This error occurs when Git cannot authenticate your SSH key with the remote repository.
-
Check if SSH key is added
Ensure that your SSH key is added to your SSH agent. Run the following command to check:ssh-add -l
If no keys are listed, you may need to add your key with:
ssh-add ~/.ssh/id_rsa
Replace
id_rsa
with the name of your private key file, if it's different. -
Add your SSH key to GitHub
If your SSH key isn't added to your GitHub account, follow these steps:- Go to
Settings
>SSH and GPG keys
on GitHub. - Click
New SSH key
, paste your public key (usually found in~/.ssh/id_rsa.pub
), and save it.
- Go to
-
Verify your SSH connection
Test your connection to GitHub using:ssh -T git@github.com
If authentication succeeds, you'll see a message like "Hi USERNAME! You've successfully authenticated."
-
Ensure SSH config is correct
Check your SSH config file (~/.ssh/config
) to ensure it has the correct settings:Host github.com User git Hostname github.com IdentityFile ~/.ssh/id_rsa
Modify the
IdentityFile
path if you're using a different SSH key. -
Retry your Git command
After ensuring everything is properly configured, try running your Git command again.
This error typically occurs when Git cannot authenticate your credentials for a remote repository.
-
Check your Git remote URL
Make sure you're using the correct repository URL (preferably an SSH URL). Run the following command to verify:git remote -v
If you're using an HTTPS URL and want to switch to SSH, update it with:
git remote set-url origin git@github.com:USERNAME/REPO.git
Replace USERNAME and REPO with your actual GitHub username and repository name.
-
Update your credentials
If you're using HTTPS and don't want to switch to SSH, ensure that your credentials are up to date:- For GitHub, use a Personal Access Token (PAT) instead of a password, cause password doesn't work anymore. You can generate a token by going to
Settings
>Developer settings
>Personal access tokens
on GitHub. - Replace your old password with this token when prompted during Git operations.
- For GitHub, use a Personal Access Token (PAT) instead of a password, cause password doesn't work anymore. You can generate a token by going to
-
Configure SSH keys (if switching to SSH)
If you switch to SSH and haven't set up your SSH keys yet, follow the steps described in this section. -
Retry your Git command
After updating your credentials, try running your Git command again.