简体   繁体   中英

git push heroku master permission denied

I am following the ruby.railstutorial. I run the command "git push heroku master" and it spits out this error.

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

I am inside my rails app "/Users/lexi87/rails_projects/first_app". Any solutions?

The best way to avoid such errors is to use one public/private key pair and not an extra key for heroku. This way you (or your system) can't choose a wrong key to login in heroku.

If you get this error, you have done something wrong. Check this site: https://devcenter.heroku.com/articles/keys

If you geht this error, the best way is to remove unnecessary keys and use only one.

If you need more than one key pair on your system, you can set one key for heroku. This is done through the following command:

heroku keys:add

Some help for Windows 7 users with Github Windows client installed:

Even though heroku toolbelt reports it found my git_hub public key and uploaded it, 'git push heroku master' failed. After taking the steps below, it works fine.

  1. Create .ssh folder under your User folder if one does not exist. If it does, delete all files in it (this assumes you are OK with starting from scratch with ssh keys).

  2. In Windows Explorer, right click the .ssh folder, and choose Git bash from the context menu. This is installed along with the Github Windows client software.

  3. In the bash window enter ssh-keygen -t rsa -C "yourname@email.com " When prompted enter a passphrase (don't lose this).

  4. Close the bash shell window.

  5. From a cmd prompt in your project's root, enter heroku keys:add . This will find and upload the key you just created from your /.ssh file to Heroku.

Now you can enter git push heroku master to push you app up to Heroku. Note: you will need to add your newly generated ssh public key to your Github account when done.

I faced the same issue. In my .ssh folder I had a file called 'Known Hosts'. I kept trying to delete and create new ssh keys it did not work. In the end I just deleted everything in .ssh including 'Known Hosts' and then created a new rsa key using:

ssh-keygen -t rsa

then I added this new key to heroku using:

heroku keys:add

then create a new heroku repo and pushed my app to it:

heroku create
git push heroku master
ssh-keygen -t rsa

Above is optional as you could also link to an existing key. Heroku will prompt to select the key in the next step.

heroku keys:add

Add your newly created key or an existing one. If you are still running into the issue, you will most likely need to add the key to your machine's list of ssh keys by performing the following:

ssh-add ~/.ssh/name_of_your_rsa

and confirm that your ssh has been added

ssh-add -l

This should get you access to push to Heroku's remote repo.

on OSX, I was having experiencing the same issue, I was getting

no such identity: /Users/me/.ssh/yourPrivateKey: No such file or directory
Permission denied (publickey).
fatal: Could not read from remote repository.

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

I tried to create a new key with ssh-keygen -t rsa then adding it with heroku keys:add, but it didn't help.

Then I found a file named config in ~/.ssh/, and inside the file there was:

ServerAliveInterval 300
ServerAliveCountMax 3

host heroku.com
    user git
    hostname heroku.com
    identityfile ~/.ssh/yourPrivateKey

So I changed yourPrivateKey to my private key filename ( id_rsa by default) aaand it worked :)

I created a key with

ssh-keygen -t rsa

and used a different filename than id_rsa (in my case heroku). I added the key to heroku with

heroku keys:add

On trying to push my master branch to heroku I always received the following error:

$ git push heroku master
The authenticity of host 'heroku.com
(50.19.85.132)' can't be established. RSA key fingerprint is
8b:48:5e:67:0e:c9:16:47:32:99:87:0c:1f:c8:60:bb. Are you sure you want
to continue connecting (yes/no)? yes Warning: Permanently added
'heroku.com,50.19.85.132' (RSA) to the list of known hosts. Permission
denied (publickey). fatal: Could not read from remote repository.

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

As I noticed git only used my id_rsa key from another ssh-access (you can check that via your git gui: Help -> SSH keys).

I renamed my .ssh directory C:\\Users\\%username%.ssh to .ssh.bak and copied my heroku private and public key (from the .ssh.bak directory) to a newly created .ssh directory and named it id_rsa (and id_rsa.pub).

Now pushing worked as expected:

git push heroku master

If you are working on Windows, be sure to use git-bash instead of Powershell/Command Prompt.

If you just want to reset your ssh keys:

  1. delete your user's .ssh dir
  2. open git-bash
  3. ssh-keygen -t rsa
  4. heroku keys:add

and then you will be able to git push.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM