git push heroku master permission denied
Ruby on-RailsGitHerokuRuby on-Rails Problem Overview
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?
Ruby on-Rails Solutions
Solution 1 - Ruby on-Rails
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
Solution 2 - Ruby on-Rails
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.
-
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).
-
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.
-
In the bash window enter
ssh-keygen -t rsa -C "[email protected]
" When prompted enter a passphrase (don't lose this). -
Close the bash shell window.
-
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.
Solution 3 - Ruby on-Rails
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
Solution 4 - Ruby on-Rails
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.
Solution 5 - Ruby on-Rails
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 :)
Solution 6 - Ruby on-Rails
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
Solution 7 - Ruby on-Rails
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:
- delete your user's .ssh dir
- open git-bash
- ssh-keygen -t rsa
- heroku keys:add
and then you will be able to git push.