A Git Error: Permission denied

I started borrowing a computer to run XCode and work on my iOS projects. It had been used by another person previously, but had been “wiped,” meaning I am not entirely sure of the process to remove the previous user’s information. I downloaded XCode, copied over my files from my personal computer, and began working on a project.

After writing a commit message, when I pushed my changes to Github, I received this error:

ERROR: Permission to learn-co-students/ios-0616-team-panda.git denied to dimacodes.

fatal: Could not read from remote repository.

Who is dimacodes? Not me. It was the user who had used this computer before I did. Github has a couple of suggested solutions when the wrong user is connected to Git on your computer.

  1.  Set your local Git email address using  git config
    git config user.email "your_email@example.com"
  2. If your commits are still not working, Github suggests checking the GIT_COMMITTER_EMAIL or GIT_AUTHOR_EMAIL variables. You can do that like this:
    # prints the value of GIT_COMMITTER_EMAIL
    # prints the value of GIT_AUTHOR_EMAIL

    If they do not contain the right value, you can change them by setting them equal to your email address.

For some users, this will be enough to override the previous email address associated with Git and allow you to push your changes up to Github using your account. However, after changing these values, I was still getting the same error message. Github did not have many more suggestions.

A couple more things we tried: recloned the project and made my changes to the freshly cloned directory. Committing and pushing the changes in the second repository, resulted in the same error message: Permission to…denied to dimacodes.

The Answer: ssh-agent

From Apple:

ssh-agent is a program to hold private keys used for public key authentication (RSA, DSA, ECDSA). The idea is that ssh-agent is started in the beginning of an X-session or a login session, and all other windows or programs are started as clients to the ssh-agent program. Through use of environment variables the agent can be located and automatically used for authentication when logging in to other machines using ssh(1).

SSH-Agent keys will remain cached via the OS Keychain. This is to save you the trouble of re-authenticating every time. In most cases, this is a great feature and your cached key will remain there forever. In order to force the removal of a cached key, you can kill it by using: ssh -a -D.

[15:01:23] .ssh
// ♥ ssh-add -D
All identities removed.
[15:01:53] .ssh
// ♥ ssh git@github.com
Permission denied (publickey).
[15:01:57] .ssh
// ♥ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/flatironschool/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/flatironschool/.ssh/id_rsa.
Your public key has been saved in /Users/flatironschool/.ssh/id_rsa.pub.
The key fingerprint is:
//Code Removed
// ♥ ls
id_rsa id_rsa.pub known_hosts
[15:02:34] .ssh
// ♥ cat id_rsa.pub | pbcopy
[15:02:39] .ssh
// ♥ ssh git@github.com
PTY allocation request failed on channel 0
Hi sheafk! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

view raw

SSH Key Cached

hosted with ❤ by GitHub


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s