ChatGPT解决这个技术问题 Extra ChatGPT

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!

Did you set a passphrase to your heroku key? And I suppose this (stackoverflow.com/a/16753800/6309) doesn't help? Or double-checking stackoverflow.com/a/16753800/6309
Sadly it still refuses to work.
sometimes this happens when heroku is in maintenance: status.heroku.com

K
Kris Hollenbeck

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

Thanks kris, Some one from the the future :) this works for me
heroku keys:add was my tutorial missed i guess... thank you! :)
The key only has to be generated if you don't have one alredy, in my case I alredy had the key and just needed to add the key to heroku
The first one is unnecessary. heroku keys:add will help you create one if you don't have a key.
Run ssh-keygen -t rsa if the RSA is not generated otherwise heroku keys:add should be suffice
t
thebradbain

I just thought I'd share that I found the answer to my own question.

Writing out my problem made it even more clear to me, and I further investigated into where I thought my problem lay: the ssh key

Turns out I was right. The issue wasn't with the key itself, but rather that I had not added it to my local Mac's list of known ssh keys. So even though my Heroku account had the correct key uploaded, my Mac could not authenticate with it because it could not find that key on my computer. The solution?

ssh-add ~/.ssh/id_rsa
#and, to confirm it's been added to the known list of keys
ssh-add -l

I would like to give credit to https://help.github.com/articles/error-permission-denied-publickey for being a good reference.


Thank you for your feedback, more accurate to your situation than my initial comment. +1
On Windows one will need to start Git Bash (right click a folder), and start an ssh-agent which is possible by running `ssh-agent` (mind the back-ticks) and then add the key as described above. I have to do this every time I start the Git Bash/ssh-agent, it forgets what was added.
I did this and it still didn't work. I ended up having to add an environment variable called HOME set to the directory my .ssh folder was in
Thanks - would never have figured this out!
This fixed my problem, not the higher voted answer, thanks :)
c
crockeea

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


Racked my brains in this until I saw your post. As soon as I made git and heroku keys the same, all was well. But don't understand why they need to be the same.
Thank you for the answer spent ages with this problem
very useful git documentation link, all works perfect
This worked for me after a couple of days of trying to figure it out. I'm surprised Heroku can stay in business with a usability issue this nasty. There should be an easier way to do this.
Thank you. Worked for me; just one thing: in the github link somewhere says to do "ssh-add". There I had an issue, but I have found solution here: stackoverflow.com/questions/17846529/…
s
sjking

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:

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 Follow the steps on gitHub to generate ssh keys Login to heroku, create a new site and add your public keys: $ heroku login ... $ heroku create $ heroku keys:add $ git push heroku master


o
oqx

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:

removed all keys from root and home/user .shh directory. generated a new key make sure to pay attention to the path of creation (/home/you/.ssh/id_rsa) or (/root/.ssh/id_rsa) check heroku keys heroku keys if keys in there clear heroku keys:clear 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. try git push heroku master now


I
Ivan Rave

My way on Windows 8

Add a directory with ssh-keygen to the system PATH variable, usually C:\Program Files (x86)\Git\bin Open CMD, go to C:\Users\Me\ 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) Add the key to Heroku heroku keys:add Select a created key from a list Go to your app directory, write some beautiful code Init a git repo git init git add . git commit -m 'chore(release): v0.0.1 Create Heroku application heroku create Deploy your app git push heroku master Open your app heroku open


u
user3484361

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>@gmail.com@heroku.com
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).

Just to say this is using Windows 8 (8.1). Also seems like the GoW ssh tool is the key, since i was able to use that without the putty pieces, and use ssh-keygen.
n
nabin

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...


r
rocLv

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.


徐啟倫

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

"Enable ssh-agent"

Download git

http://git-scm.com/

Install it Enable ssh-agent

C:\Program Files\Git\cmd

start-ssh-agent

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


y
ytv

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>

A
Alin Ciocan

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


0
00imvj00

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.


F
FullTimeCoderPartTimeSysAdmin

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.


In my case, the issue seems to be related to ":"'s in ssh remote paths. (Git 1.9.4 for windows.) For some reason ssh://git@host:repo fails with "fatal: Could not read from remote repository" while ssh://git@host/repo" succeeds.