How to fix fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. in Git
This error occurs when Git cannot establish a connection to the remote repository. Common causes include SSH key issues, incorrect repository URLs, missing access permissions, or network problems preventing the connection.
Quick fix
Fixes fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
ssh -T git@github.com- Verify your SSH connection to the remote host
- Check if your SSH key exists and is loaded
- Generate a new SSH key if needed
- Add your SSH key to your Git hosting account
ssh -T git@github.comfatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
What this error means
The "fatal: Could not read from remote repository" error indicates that Git attempted to communicate with a remote repository (like one hosted on GitHub, GitLab, or Bitbucket) but failed to establish a connection. This is a generic error that can stem from several different underlying issues. The error message "Please make sure you have the correct access rights and the repository exists" provides two main hints: 1. **Access rights**: Your authentication method (SSH keys or HTTPS credentials) may not be configured correctly, or you may not have permission to access the repository 2. **Repository exists**: The remote URL might be incorrect, the repository may have been deleted or renamed, or it might be a private repository you cannot access This error commonly appears when: - Cloning a repository for the first time - Pushing or pulling changes - Fetching updates from upstream - Working with submodules that reference remote repositories
Typical symptoms
- Git push, pull, clone, or fetch commands fail with 'fatal: Could not read from remote repository'
- SSH operations to the remote host fail with 'Permission denied (publickey)'
- Error appears after changing computers or generating new SSH keys
- Error occurs in CI/CD pipelines when accessing private repositories
- Submodule updates fail with repository access errors
- Error appears after repository was renamed, moved, or made private
Common causes
- SSH key not added to your GitHub/GitLab/Bitbucket account
- SSH agent not running or key not loaded into the agent
- Incorrect remote URL (typo in repository name or organization)
- Repository is private and you don't have access
- Repository has been deleted, renamed, or moved
- SSH key permissions are incorrect (too open)
- Wrong SSH key being used (multiple keys, wrong identity)
- Firewall or proxy blocking SSH connections (port 22)
- GitHub/GitLab host not in known_hosts file
- Using HTTPS URL but Git is configured for SSH (or vice versa)
How to fix "fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists."
First, test if you can connect to the remote Git server via SSH:
For GitHub:
ssh -T git@github.comFor GitLab:
ssh -T git@gitlab.comFor Bitbucket:
ssh -T git@bitbucket.orgExpected success message (GitHub):
Hi username! You've successfully authenticated, but GitHub does not provide shell access.If you see "Permission denied (publickey)", your SSH key is not configured correctly. If you see a connection timeout, there may be network/firewall issues.
Verify that you have an SSH key and it's loaded into the SSH agent:
Check for existing SSH keys:
ls -la ~/.sshLook for files like id_ed25519, id_rsa, id_ecdsa (private keys) and their .pub counterparts.
Start the SSH agent and add your key:
# Start the agent
eval "$(ssh-agent -s)"
# Add your key (replace with your key name)
ssh-add ~/.ssh/id_ed25519
# or
ssh-add ~/.ssh/id_rsaVerify the key is loaded:
ssh-add -lIf no keys are loaded, you'll see "The agent has no identities."
If you don't have an SSH key, generate one:
# Generate a new ED25519 key (recommended)
ssh-keygen -t ed25519 -C "your_email@example.com"
# Or generate an RSA key (for older systems)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"When prompted:
- Press Enter to accept the default file location
- Enter a passphrase (recommended) or press Enter for no passphrase
Add the key to your SSH agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519Copy the public key to your clipboard:
# macOS
cat ~/.ssh/id_ed25519.pub | pbcopy
# Linux (with xclip)
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard
# Windows (Git Bash)
cat ~/.ssh/id_ed25519.pub | clipAdd the public key to your GitHub/GitLab/Bitbucket account:
GitHub:
1. Go to Settings > SSH and GPG keys > New SSH key
2. Give it a descriptive title
3. Paste your public key
4. Click "Add SSH key"
GitLab:
1. Go to Preferences > SSH Keys
2. Paste your public key
3. Set an expiration date (optional)
4. Click "Add key"
Bitbucket:
1. Go to Personal settings > SSH keys
2. Click "Add key"
3. Paste your public key
4. Click "Add key"
Verify it works:
ssh -T git@github.comVerify your remote URL is correct:
git remote -vExample output:
origin git@github.com:username/repo.git (fetch)
origin git@github.com:username/repo.git (push)Common issues to check:
- Typo in username or repository name
- Repository was renamed or moved to a different organization
- Using SSH URL (git@github.com:) but SSH isn't set up
- Using HTTPS URL (https://) but need to use SSH
Update the remote URL if needed:
# Change to SSH
git remote set-url origin git@github.com:username/repo.git
# Change to HTTPS
git remote set-url origin https://github.com/username/repo.gitVerify the repository exists by visiting it in your browser.
SSH requires strict permissions on key files. Fix permissions if they're too open:
# Set correct permissions on .ssh directory
chmod 700 ~/.ssh
# Set correct permissions on private key
chmod 600 ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_rsa
# Set correct permissions on public key
chmod 644 ~/.ssh/id_ed25519.pub
chmod 644 ~/.ssh/id_rsa.pub
# Set correct permissions on config file
chmod 600 ~/.ssh/configIf permissions are too open, SSH will refuse to use the key and you'll see warnings like:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@If you have multiple SSH keys, configure SSH to use the right one for each host:
Create or edit ~/.ssh/config:
nano ~/.ssh/configAdd configuration for your Git host:
# GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_github
IdentitiesOnly yes
# GitLab
Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_ed25519_gitlab
IdentitiesOnly yes
# Work GitHub (using different key)
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work
IdentitiesOnly yesFor the work alias, update your remote:
git remote set-url origin git@github-work:company/repo.gitSome networks block SSH port 22. Use port 443 instead:
Test if port 443 works:
ssh -T -p 443 git@ssh.github.comConfigure SSH to always use port 443 for GitHub:
Edit ~/.ssh/config:
Host github.com
HostName ssh.github.com
Port 443
User git
IdentityFile ~/.ssh/id_ed25519Or use HTTPS with credential caching:
# Switch to HTTPS
git remote set-url origin https://github.com/username/repo.git
# Cache credentials for 1 hour
git config --global credential.helper 'cache --timeout=3600'
# Or store credentials permanently (less secure)
git config --global credential.helper storeUse verbose mode to diagnose SSH connection problems:
# Verbose SSH connection test
ssh -vT git@github.comKey things to look for in the output:
1. "Offering public key" - Shows which key SSH is trying to use
2. "Server accepts key" - Key was accepted
3. "Permission denied" - Authentication failed
4. "Connection timed out" - Network/firewall issue
Common debug patterns:
# Key not found
debug1: No more authentication methods to try.
Permission denied (publickey).
# Wrong key being offered
debug1: Offering public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey
# Key file permissions issue
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@If this is your first time connecting to a host, SSH will ask you to verify its authenticity:
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
Are you sure you want to continue connecting (yes/no/[fingerprint])?Verify the fingerprint against the official documentation:
- GitHub: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
- GitLab: https://docs.gitlab.com/ee/user/gitlab_com/#ssh-host-keys-fingerprints
If it matches, type `yes` to add to known_hosts.
In CI/CD environments, you may need to pre-populate known_hosts:
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hostsAdvanced notes
Deploy Keys vs User SSH Keys:
For CI/CD pipelines accessing private repositories, consider using deploy keys:
- Deploy keys are repository-specific SSH keys
- They provide read-only access by default (can be set to read-write)
- Safer than using personal SSH keys in CI/CD
Generate and add a deploy key:
# Generate a key specifically for the repository
ssh-keygen -t ed25519 -f ~/.ssh/deploy_myrepo -C "deploy-key-myrepo"Then add the public key as a deploy key in your repository settings.
Personal Access Tokens (PAT) for HTTPS:
If SSH doesn't work in your environment, use a Personal Access Token with HTTPS:
git clone https://oauth2:YOUR_TOKEN@github.com/username/repo.git
# Or configure credential helper to store the token
git config --global credential.helper store
git clone https://github.com/username/repo.git
# Enter your username and PAT when promptedGitHub CLI Alternative:
The GitHub CLI (gh) can handle authentication automatically:
# Install and authenticate
gh auth login
# Clone repositories
gh repo clone username/repoSubmodule Issues:
If the error occurs with submodules:
# Update submodule URLs to match your access method
git config --file=.gitmodules submodule.mysubmodule.url git@github.com:org/submodule.git
git submodule sync
git submodule update --init --recursiveSSH Agent Forwarding:
When working on remote servers and needing access to private repos:
# Connect with agent forwarding
ssh -A user@server
# On the server, verify your key is available
ssh-add -lWindows-Specific Issues:
On Windows, ensure you're using the Git Bash SSH, not Windows OpenSSH:
# Check which SSH Git is using
git config --global core.sshCommand
# Force Git to use Git Bash SSH
git config --global core.sshCommand "C:/Program Files/Git/usr/bin/ssh.exe"Frequently asked questions
- What does "fatal: Could not read from remote repository. Please make sure you hav" mean?
- The "fatal: Could not read from remote repository" error indicates that Git attempted to communicate with a remote repository (like one hosted on GitHub, GitLab, or Bitbucket) but failed to establish a connection. This is a generic error that can stem from several different underlying issues. The error message "Please make sure you have the correct access rights and the repository exists" provides two main hints: 1.
- How do I fix "fatal: Could not read from remote repository. Please make sure you hav"?
- This error occurs when Git cannot establish a connection to the remote repository. Common causes include SSH key issues, incorrect repository URLs, missing access permissions, or network problems preventing the connection.
- What causes "fatal: Could not read from remote repository. Please make sure you hav"?
- SSH key not added to your GitHub/GitLab/Bitbucket account SSH agent not running or key not loaded into the agent Incorrect remote URL (typo in repository name or organization)
- Is the "fatal: Could not read from remote repository. Please make sure you hav" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Git Official Documentation
- 📖Error: Permission denied (publickey) - GitHub Docs(Official Docs)
- 📖Working with Remotes - Git Documentation(Official Docs)
- 📖git-remote Documentation - Git(Official Docs)
- 💬
- 💬
- 💬
- 💬