[git] Heroku 'Permission denied (publickey) fatal: Could not read from remote repository' woes

I've searched around for many hours on end looking to a solution to my seemingly easy-to-fix problem. It's not that my search turned up nothing, it's that my search turned up so many different solutions -none of which have worked.

Anyways, I am simply unable to push, pull, or fetch from my Heroku repository from my Mac. Every attempt gives me (as if it's mocking me) the following error:

'Permission denied (publickey). fatal: Could not read from remote repository.'

I've tried (and re-tried) to fix it in many different ways. As I've said, I've spent a good chunk of the last two days searching around for an answer. Here are some of the things I've tried:

  • heroku keys:clear followed by heroku keys:add
  • Regenerating an ssh key on my own with 'ssh-keygen -t rsa'
  • Clearing out my .ssh directory, followed by heroku keys:clear, followed by generating an ssh key
  • Deleting my app on heroku and recreating one (fortunately not much was on there)

I can fetch from my GitHub repository fine, so I know it's not network connectivity (pinging heroku also works).

As a makeshift solution (that I hope doesn't turn into a permanent one), I've logged in to my Ubuntu Amazon AWS ec2 instance. Pulling and pushing to and from Heroku works perfectly. For this reason, I still feel as if the problem lies with the ssh key on my Mac. Both keys show up under my Heroku account. Does the email address at the end of the key matter?

EDIT: I can push and pull from GitHub fine (I'm not using ssh, however), so why not Heroku?

At this point I'm willing to try anything. Thanks!

This question is related to git heroku ssh repository public-key

The answer is


I had the exact same error (on windows 7) and the cause was different. I solved it in a different way so I thought I'd add the cause and solution here for others.

Even though the error seemed to point to heroku really the error was saying "Heroku can't get to the git repository". I swore I had the same keys on all the servers because I created it and uploaded it to one after the other at the same time.

After spending almost a day on this I realized that because git was only showing me the fingerprint and not the actual key. I couldn't verify that it's key matched the one on my HD or heroku. I looked in the known hosts file and guess what... it shows the keys for each server and I was able to clearly see that the git and heroku public keys did not match.

1) I deleted all the files in my key folder, the key from github using their website, and the key from heroku using git bash and the command heroku keys:clear

2) Followed github's instructions here to generate a new key pair and upload the public key to git

3) using git bash- heroku keys:add to upload the same key to heroku.

Now git push heroku master works.

what a nightmare, hope this helped somebody.

Bryan


I use this method to solve this problem Maybe you can try it

"Enable ssh-agent"

  1. Download git

http://git-scm.com/

  1. Install it

  2. Enable ssh-agent

C:\Program Files\Git\cmd

start-ssh-agent

The message disapper after I agent enabled Hope this will help you


I had a similar heroku ssh error that I could not resolve.

As a workaround, I used the new heroku http-git feature (http transport for "heroku" remote instead of ssh). Details here: https://devcenter.heroku.com/articles/http-git

(Short version: if you have a project already setup the standard way, run heroku git:remote --http-init to change "heroku" remote to http.)

A good quick work around if you don't have time to fix/troubleshoot an ssh issue.


Had a similar issue, and tried lots of things. Ultimately what worked for me, was to have Gnu on Windows installed (https://github.com/bmatzelle/gow/releases) , and ensure that it was using the ssh tool inside that directory and not the one with Git. Once installed test with (ensure if its in your environment PATH that it preceds Git\bin)

C:\Git\htest2>which ssh
C:\Program Files (x86)\Gow\bin\ssh.BAT

I used putty and pageant as described here:http://rubyonrailswin.wordpress.com/2010/03/08/getting-git-to-work-on-heroku-on-windows-using-putty-plink-pageant/

Once the keys had been sent to heroku (heroku keys:add c:\Users\Person.ssh\id_rsa.pub), use

ssh -v <username>@heroku.com 

and ensure that your stack is showing use of Putty - ie a working stack:

Looking up host "heroku.com"
Connecting to 50.19.85.132 port 22
Server version: SSH-2.0-Twisted
Using SSH protocol version 2
**We claim version: SSH-2.0-PuTTY_Release_0.62**
Using Diffie-Hellman with standard group "group1"
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 2048 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Pageant is running. Requesting keys.
Pageant has 1 SSH-2 keys
Using username "*--ommitted for security--*".
**Trying Pageant key #0**
Authenticating with public key "rsa-key-20140401" from agent
Sending Pageant's response
Access granted
Opened channel for session
Server refused to allocate pty
Server refused to start a shell/command
FATAL ERROR: Server refused to start a shell/command

One that was running previously and failed:

C:\Git\htest2>ssh -v <username>@[email protected]
OpenSSH_4.6p1, OpenSSL 0.9.8e 23 Feb 2007
debug1: Connecting to heroku.com [50.19.85.156] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Person/.ssh/identity type -1
debug1: identity file /c/Users/Person/.ssh/id_rsa type 1
debug1: identity file /c/Users/Person/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version Twisted
debug1: no match: Twisted
debug1: Enabling compatibility mode for protocol 2.0
**debug1: Local version string SSH-2.0-OpenSSH_4.6**
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Host 'heroku.com' is known and matches the RSA host key.
debug1: Found key in /c/Users/Person/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Users/Person/.ssh/identity
debug1: Offering public key: /c/Users/Person/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 277
debug1: Trying private key: /c/Users/Person/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).

I had the same issue. And I tried to reset my keys as everyone said, but it still didn't worked. For was because I renamed the app.

So what I did was to reset my keys and also rename app from console. Check this question for more information: Heroku push app problem


i had the same case on linux ubuntu and just fixed it, it seems that OS was confused between the /root/.ssh/ and home/user/.ssh/ dir, what i did was:

  1. removed all keys from root and home/user .shh directory.
  2. generated a new key make sure to pay attention to the path of creation (/home/you/.ssh/id_rsa) or (/root/.ssh/id_rsa)
  3. check heroku keys heroku keys
  4. if keys in there clear heroku keys:clear
  5. heroku keys:add now in here if heroku couldn't find a key and asked to generate one right no, and this mean you have the same issue as mine, do the add command like this heroku keys:add /root/.ssh/id_rsa.pub the path that you'll add will be the one that you got in step 2.
  6. try git push heroku master now

I'd like to add another solution since I didn't see it here. My problem was that heroku was linking to the wrong url (since I kept playing around with url names). Editing the remote url solved my problem:

git remote set-url heroku <heroku-url-here>

The problem I was having is that I was only using https for my GitHub account. I needed to make sure that my GitHub account was setup for ssh access and that GitHub and heroku were both using the same public keys. These are the steps I took:

  1. Navigate to the ~/.ssh directory and delete the id_rsa and id_rsa.pub if they are there. I started with new keys, though it might not be necessary.

    $ cd ~/.ssh
    $ rm id_rsa id_rsa.pub
    
  2. Follow the steps on gitHub to generate ssh keys
  3. Login to heroku, create a new site and add your public keys:

    $ heroku login
    ...
    $ heroku create
    $ heroku keys:add
    $ git push heroku master
    

you need to create a new ssh key by typing the following - ssh-keygen -t rsa

Then you need to add: - heroku keys:add

Then if you type - heroku open

The problem has been solved.

It worked for me anyway, you could give it a try...


I know this has already been answered. But I would like to add my solution as it may helpful for others in the future..

A common key error is: Permission denied (publickey). You can fix this by using keys:add to notify Heroku of your new key.

In short follow these steps: https://devcenter.heroku.com/articles/keys

First you have to create a key if you don't have one:

ssh-keygen -t rsa

Second you have to add the key to Heroku:

heroku keys:add

I got the same error, and because I have 4 ssh-keys, so I tried follow:

ssh-keygen -t rsa
heroku keys:add

then, four options show:

1) github_rsa.pub
2) id_boot2docker.pub
3) id_rsa.pub
4) sshkey.pub

I choose 3), the newest one

Then, I fix the error.


My way on Windows 8

  1. Add a directory with ssh-keygen to the system PATH variable, usually C:\Program Files (x86)\Git\bin

  2. Open CMD, go to C:\Users\Me\

  3. Generate SSH key ssh-keygen -t rsa

    Enter file in which to save the key (//.ssh/id_rsa): .ssh/id_rsa (change a default incorrect path to .ssh/somegoodname_rsa)

  4. Add the key to Heroku heroku keys:add

    Select a created key from a list

  5. Go to your app directory, write some beautiful code

  6. Init a git repo git init git add . git commit -m 'chore(release): v0.0.1

  7. Create Heroku application heroku create

  8. Deploy your app git push heroku master

  9. Open your app heroku open


SO So So simple solution , go to c:/Users/user_name/.ssh/ and delete all pub / private key pairs , this way heroku will generate keys for you.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to heroku

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip Can't push to the heroku ImproperlyConfigured: You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings How to enable CORS in flask Error: Cannot pull with rebase: You have unstaged changes How to solve error "Missing `secret_key_base` for 'production' environment" (Rails 4.1) Failed to execute 'postMessage' on 'DOMWindow': The target origin provided does not match the recipient window's origin ('null') 'heroku' does not appear to be a git repository Heroku 'Permission denied (publickey) fatal: Could not read from remote repository' woes How do I set up DNS for an apex domain (no www) pointing to a Heroku app?

Examples related to ssh

Starting ssh-agent on Windows 10 fails: "unable to start ssh-agent service, error :1058" How to solve "sign_and_send_pubkey: signing failed: agent refused operation"? key_load_public: invalid format ssh connection refused on Raspberry Pi Getting permission denied (public key) on gitlab Verify host key with pysftp Can't connect to Postgresql on port 5432 Checkout Jenkins Pipeline Git SCM with credentials? How to open remote files in sublime text 3 how to setup ssh keys for jenkins to publish via ssh

Examples related to repository

Kubernetes Pod fails with CrashLoopBackOff Project vs Repository in GitHub How to manually deploy artifacts in Nexus Repository Manager OSS 3 How to return a custom object from a Spring Data JPA GROUP BY query How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts? How do I rename both a Git local and remote branch name? Can't Autowire @Repository annotated interface in Spring Boot How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning? git repo says it's up-to-date after pull but files are not updated Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?

Examples related to public-key

key_load_public: invalid format Verify host key with pysftp Github permission denied: ssh add agent has no identities git push: permission denied (public key) Heroku 'Permission denied (publickey) fatal: Could not read from remote repository' woes Using scp to copy a file to Amazon EC2 instance? How to ssh connect through python Paramiko with ppk public key Adding a public key to ~/.ssh/authorized_keys does not log me in automatically Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly GitHub: Permission denied (publickey). fatal: The remote end hung up unexpectedly