Could not read from remote repository - GIT

Unable to push to the Git remote, receiving an error message that states: "Could not read from remote repository. Please ensure you have the correct access rights and that the repository exists."

ERROR: Permission to account/repo.git denied to username.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

If you have encountered this "Could not read from remote repository" error, 

it likely indicates that you've used the same SSH key across multiple GitHub accounts, resulting in this issue. To verify this, try adding your SSH key to your GitHub account; if it's already in use, you'll receive an error message indicating so.

✅ To resolve this problem, you'll need to utilize distinct SSH keys for each of your GitHub accounts.

How to setup multiple SSH Keys for different github account?

To set up multiple SSH keys for different GitHub accounts, follow these steps:

Step 1:

Generate SSH keys: First, you need to generate SSH keys for each GitHub account you want to use.

# Generate SSH key for the first GitHub account
ssh-keygen -t rsa -C "your_email@example.com"
# This will prompt you to save the key. Give it a unique name like id_rsa_personal or id_rsa_work.

# Generate SSH key for the second GitHub account
ssh-keygen -t rsa -C "your_email@example.com"
# Again, give this key a unique name like id_rsa_work or id_rsa_personal.

Make sure to replace "your_email@example.com" with the email associated with each GitHub account.

Step 3: 

Add SSH keys to SSH agent: Next, you need to add these SSH keys to the SSH agent.

# Start the SSH agent
eval "$(ssh-agent -s)"

# Add the first SSH key
ssh-add ~/.ssh/id_rsa_personal

# Add the second SSH key
ssh-add ~/.ssh/id_rsa_work

Step 4: 

Associate SSH keys with GitHub accounts: Now, you need to associate each SSH key with the corresponding GitHub account.

# Open SSH config file
nano ~/.ssh/config
Add the following configuration:
# Personal GitHub account
Host github.com-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_personal

# Work GitHub account
Host github.com-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_work

Save and close the file.

Step 5: 

Test the configuration: To make sure everything is set up correctly, you can test the SSH connection to both GitHub accounts.

ssh -T git@github.com-personal
ssh -T git@github.com-work

You should receive a message confirming the successful authentication for each account. 

Now you can use different SSH keys for different GitHub accounts on your Ubuntu system. When you clone or interact with repositories, make sure to use the appropriate github.com-personal or github.com-work URLs instead of the standard github.com URL.

Thank You!