git push heroku master permission denied - ruby-on-rails

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.
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 "yourname#email.com" 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.

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

Related

not able to pip install from private repo in docker [duplicate]

I'm on Mac Snow Leopard and I just installed git.
I just tried
git clone git#thechaw.com:cakebook.git
but that gives me this error:
Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
What am I missing?
I've also tried doing ssh-keygen with no passphase but still same error.
If the user has not generated a ssh public/private key pair set before
This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)
First start by setting up your own public/private key pair set. This
can use either DSA or RSA, so basically any key you setup will work.
On most systems you can use ssh-keygen.
First you'll want to cd into your .ssh directory. Open up the terminal and run:
cd ~/.ssh && ssh-keygen
Next you need to copy this to your clipboard.
On OS X run: cat id_rsa.pub | pbcopy
On Linux run: cat id_rsa.pub | xclip
On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to #orion elenzil)
Add your key to your account via the website.
Finally setup your .gitconfig.
git config --global user.name "bob"
git config --global user.email bob#...
(don't forget to restart your command line to make sure the config is reloaded)
That's it you should be good to clone and checkout.
Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to #Lee Whitney)
[1]: https://github.com/sitaramc/gitolite
-
If the user has generated a ssh public/private key pair set before
check which key have been authorized on your github or gitlab account settings
determine which corresponding private key must be associated from your local computer
eval $(ssh-agent -s)
define where the keys are located
ssh-add ~/.ssh/id_rsa
More extensive troubleshooting and even automated fixing can be done with:
ssh -vT git#github.com
Alternatively, according to below comments, we could issue:
ssh -vT git#gitlab.com
or substitute gitlab/github with whatever Git Instance your organisation is running.
Source: https://help.github.com/articles/error-permission-denied-publickey/
This error can happen when you are accessing the SSH URL (Read/Write) instead of Git Read-Only URL but you have no write access to that repo.
Sometimes you just want to clone your own repo, e.g. deploy to a server. In this case you actually only need READ-ONLY access. But since that's your own repo, GitHub may display SSH URL if that's your preference. In this situation, if your remote host's public key is not in your GitHub SSH Keys, your access will be denied, which is expected to happen.
An equivalent case is when you try cloning someone else's repo to which you have no write access with SSH URL.
In a word, if your intent is to clone-only a repo, use HTTPS URL (https://github.com/{user_name}/{project_name}.git) instead of SSH URL (git#github.com:{user_name}/{project_name}.git), which avoids (unnecessary) public key validation.
Update: GitHub is displaying HTTPS as the default protocol now and this move can probably reduce possible misuse of SSH URLs.
The github help link helped me sort out this problem. Looks like the ssh key was not added to the ssh-agent. This is what I ended up doing.
Command 1:
Ensure ssh-agent is enabled. The command starts the ssh-agent in the background:
eval "$(ssh-agent -s)"
Command 2:
Add your SSH key to the ssh-agent:
ssh-add ~/.ssh/id_rsa
Got the same error report.
Fixed with using the HTTPS instead of the SSH protocol. Since I don't want to set "SSH keys" for a test PC.
Change URL to HTTPS when clone:
git clone https://github.com/USERNAME/REPOSITORY.git
My problem is a little bit different: I have the URL set to SSH when adding an existing local repo to remote, by using:
git remote add origin ssh://github.com/USERNAME/REPOSITORY.git
To fix it, reset the URL to HTTPS:
git remote set-url origin https://github.com/USERNAME/REPOSITORY.git
BTW, you may check your URL using the command:
git remote -v
origin https://github.com/USERNAME/REPOSITORY.git (fetch)
origin https://github.com/USERNAME/REPOSITORY.git (push)
Hope this will help some one like me. :D
Another possibility on Windows, which is not covered in any of these answers, and is not covered in the git or github docs on troubleshooting:
git may be using a different openssh executable than you think it is.
I was receiving the Permission denied (public key) error when trying to clone or pull from github and ssh.dev.azure.com, and I'd followed all the instructions and verified that my SSH keys were setup correctly (from SSH's standpoint) using ssh -vT git#github.com and ssh -vT git#ssh.dev.azure.com. And was still getting these errors:
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I eventually figured out that the problem is that Git for Windows, and Windows, both have their own versions of openssh. This is documented here: https://github.com/desktop/desktop/issues/5641
I was relying on the Windows ssh-agent service to store my ssh key passphrases, so git (with it's separate version of openssh) couldn't read my private keys. I consider it a bug that this error message is used - it's misleading.
The fix was:
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
Or in your ~/.gitconfig:
[core]
sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'
Perhaps this will be fixed in git for Windows soon, but this is the 2nd time I've wasted time on this issue.
I was struggling with the same problem that's what I did and I was able to clone the repo. I followed this procedure for Mac.
First Step: Checking if we already have the public SSH key.
Open Terminal.
Enter ls -al ~/.ssh to see if existing SSH keys are present:
Check the directory list to see if you already have a public SSH key. Default public is one of the following d_dsa.pub, id_ecdsa.pub, id_ed25519.pub, id_rsa.pub.
If you don't find then go to step 2 otherwise follow step 3
Step 2: Generating public SSH key
Open Terminal.
Enter the following command with a valid email address that you use for github ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
You will see the following in your terminal Generating public/private rsa key pair. When it prompts to"Enter a file in which to save the key," press Enter. This accepts the default file location. When it prompts to Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] Just press enter again.
At the prompt, "Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don't want to Enter same passphrase again: [Type passphrase again] press enter again
This will generate id_rsa.pub
Step 3: Adding your SSH key to the ssh-agent
Interminal type eval "$(ssh-agent -s)"
Add your SSH key to the ssh-agent. If you are using an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file. Enter this command $ ssh-add -K ~/.ssh/id_rsa
Now copy the SSH key and also add it to you github account
In terminal enter this command with your ssh file name pbcopy < ~/.ssh/id_rsa.pub This will copy the file to your clipboard
Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.
This works for me:
ssh-add ~/.ssh/id_rsa
Visual guide (Windows)
1 of 2. Git batch side
1.1. Open git batch (Download her)
1.2. Paste the text below (Change to your GitHub account email)
$ ssh-keygen -t rsa -b 4096 -C "your_email#example.com"
1.3. Press Enter (Accepts the default file location)
1.4. Click Enter Twice (Or set SSH key passphrases - Gitbub passphrases docs)
> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]
1.5. The key generate:
Your identification has been saved in /c/Users/user/.ssh/id_rsa...
1.6. Copy the SSH key to your clipboard.
$ clip < ~/.ssh/id_rsa.pub
2 of 2. Github website user side
Under user setting
SSH and GPG keys => New SSH key:
Paste the code from step 1.6
Done :)
If someone doesn't want to use SSH use HTTPS :
Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
If your problem appears out of the blue recently (the latter half of 2021), it may have been caused by incompatible hash algorithms.
As of this post (Oct 2021), the latest version of Git for windows is 2.33.1 (release note), who has embraced the latest OpenSSH 8.8p1 (release note), who in turn has deprecated SHA-1. Meanwhile, if your remote Git repository still sticks to SHA-1, you'll fail the authentication.
To see whether you could have fallen into this case, check the version of your software by:
ssh -V
git --version
Then you should check the "Potentially-incompatible changes" section of OpenSSH 8.8/8.8p release note.
TL;DR
Solution 1: Enable SHA-1 again by adding this to your ~/.ssh/config file:
Host <remote>
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedAlgorithms +ssh-rsa
Remember to replace <remote> with the hostname of your remote repository.
Solution 2: Regenerate your key pair using ECDSA or Ed25519, instead of RSA. For example:
ssh-keygen -t ecdsa -C <comment>
Remember to replace <comment> with your own mnemonic phrase. Then, upload the generated public key to your remote repository.
FYI, I encountered this prompt message when accessing Gitee.com, who uses golang.org/x/crypto/ssh on their server and has posted a page on this issue here (in Mandarin).
git#gitee.com: Permission denied (publickey).
Note that (at least for some projects) you must have a github account with an ssh key.
Look at the keys listed in your authentication agent (ssh-add -l)
(if you don't see any, add one of your existing keys with ssh-add /path/to/your/key (eg: ssh-add ~/.ssh/id_rsa))
(if you don't have any keys, first create one. See: http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html or just google ssh-keygen)
To verify that you have a key associated with your github account:
Go to: https://github.com/settings/ssh
You should see at least one key with a hash key matching one of the hashes you saw when you typed ssh-add -l just a minute ago.
If you don't, add one, then try again.
I met the same issue because of I was thought the difference between SSH and HTTPS is
https://github.com/USERNAME/REPOSITORY.git
ssh://github.com/USERNAME/REPOSITORY.git
So I changed from HTTPS to SSH just by changing https:// to ssh:// nothing on the end of the url was changed.
But the truth is:
https://github.com/USERNAME/REPOSITORY.git
git#github.com:USERNAME/REPOSITORY.git
Which means I changed ssh://github.com/USERNAME/REPOSITORY.git to git#github.com:USERNAME/REPOSITORY.git it works.
Stupid error but hope helps someone!
These are the steps I followed in windows 10
Open Git Bash.
Generate Public Key:
ssh-keygen -t rsa -b 4096 -C "youremailaddress#xyz.com"
Copy generated key to the clipboard (works like CTRL+C)
clip < ~/.ssh/id_rsa.pub
Browser, go to Github => Profile=> Settings => SSH and GPG keys => Add Key
Provide the key name and paste clipboard (CTRL+V).
Finally, test your connection (Git bash)
ssh -T git#github.com
Thanks!
Please try this if nothing is worked out
Generate personal Access token (Setting -> Developer settings -> Personal access tokens -> Generate new token)
git remote set-url origin https://<TOEKN>#github.com/USERNAME/REPOSITORY.git
Note: If a password popup comes, try to enter the token only (try twice)
I had a slight different situation, I was logged on to a remote server and was using git on the server, when I ran any git command I got the same message
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
The way I fixed it was by changing the file /etc/ssh_config on my Mac.
from
ForwardAgent no
to
ForwardAgent yes
I had to copy my ssh keys to the root folder.
Google Cloud Compute Engine running Ubuntu 18.04
sudo cp ~/.ssh/* /root/.ssh/
Solution using gh i.e. Github's official CLI
gh installation
brew install gh
gh login or authentication via cli
gh auth login
repo clone
gh repo clone <username or orgname>/<repo-name>
Example: gh repo clone keshavdulal/sample-repo
Rant: I too was bashing my head when git clone suddenly decided not to work anymore and I don't have the patience or brainpower to relearn ssh/public keys/cryptography from scratch just to clone a freaking repo I already have access to. Also surprised no one mentioned gh in the answers yet
Guys this is how it worked for me:
Open terminal and go to user [See attached image]
Open .ssh folder and make sure it doesn't have any file like id_rsa or id_rsa.pub otherwise sometimes it wont properly rewrite files
git --version [Check for git installation and version]
git config --global user.email "your email id"
git config --global user.name "your name"
git config --list [make sure you have set your name & email]
cd ~/.ssh
ssh-keygen, it prompts for saving file, allow it
cat ~/.ssh/id_rsa.pub [Access your public key & copy the key to gerrit settings]
Note: You should not be using the sudo command with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it's probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won't be using the same keys that you generated
ALWAYS CHECK GITHUB FOR SSH-KEYS GENERATION PROCEDUR, NOT SOME OUTDATED BLOG
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
There you can see that keys are generated with:
ssh-keygen -t ed25519 -C "your_email#example.com"
So algorithm is ed25519 not rsa or anything else.
Are you in a corporate environment? Is it possible that your system variables have recently changed? Per this SO answer, ssh keys live at %HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub. So if %HOMEDRIVE% recently changed, git doesn't know where to look for your key, and thus all of the authentication stuff.
Try running ssh -vT git#github.com. Take note of where the identity file is located. For me, that was pointing not to my normal \Users\MyLogin but rather to a network drive, because of a change to environment variables pushed at the network level.
The solution? Since my new %HOMEDRIVE% has the same permissions as my local files, I just moved my .ssh folder there, and called it a day.
I hit this error because I needed to give my present working directory permissions 700:
chmod -R 700 /home/ec2-user/
On Windows, make sure all your apps agree on HOME. Msys will surprisingly NOT do it for you. I had to set an environment variable because ssh and git couldn't seem to agree on where my .ssh directory was.
One of the easiest way
go to terminal-
git push <Git Remote path> --all
The basic GIT instructions did not make a reference to the SSH key stuff. Following some of the links above, I found a git help page that explains, step-by-step, exactly how to do this for various operating systems (the link will detect your OS and redirect, accordingly):
http://help.github.com/set-up-git-redirect/
It walks through everything needed for GITHub and also gives detailed explanations such as "why add a passphrase when creating an RSA key." I figured I'd post it, in case it helps someone else...
The easiest solution to this, when you are trying to push to a repository with a different username is:
git remote set-url origin https://USERNAME#github.com/USERNAME/PROJECTNAME.git
I helped the following:
Open Terminal (Git Bash)
Remove all files in directory .ssh or rename and create new .ssh folder.
To follow in the steps of the instructions:
Generating a new SSH key
Adding your SSH key to the ssh-agent
System: Windows 10.
In addition to Rufinus' reply, the shortcut to copy your ssh key to the clipboard in Windows is:
type id_rsa.pub | clip
Refs:
Print to standard output
Copy command line output to clipboard
If you have more than one key you may need to do
ssh-add private-keyfile
Its pretty straight forward. Type the below command
ssh-keygen -t rsa -b 4096 -C "youremailid#yourdomain.com"
Generate the SSH key. Open the file and copy the contents. Go to GitHub setting page , and click on SSH key . Click on Add new SSH key, and paste the contents here. That's it :) You shouldn't see the issue again.
I deleted node_modules/ package-lock.json and yarn.lock files. Ran npm i again. This resolved the issue for me.

Heroku Without Toolbelt On Windows

Would like to be able to push to, and clone from, Heroku without the toolbelt.
I've got Win10x64, Rails 2.4.4, Ruby 2.2.3
The answer is to link to Heroku using ssh:
You need to download & install git
You need to generate your SSH key
You need to "link" your Heroku app to your computer's SSH key
You should then be able to push/clone from Heroku
--
This answer helped get it working:
https://serverfault.com/a/198709/241166
You have to set the HOME path of your ssh before performing ssh-keygen -t rsa (this actually doesn't seem to be the case; you should be able to browse to the required output folder & run ssh-keygen -t rsa):
ssh has its keys in c:/Users/[username]/.ssh by default.
This will set the .pub file, which you'll be able to open using a text editor (notepad will do):
You then need to copy the contents of the generated .pub file to Heroku's Account Settings option:
If you need to remove Heroku from known_hosts, you'll want to use:
ssh-keygen -H -F heroku.com
ssh-keygen -R heroku.com
--
Next, you need to authenticate with Heroku.
ssh -v git#heroku.com
This should then allow you to connect via SSH to Heroku from that system.
It may say a permission denied error - you should be able to ignore that, cd to the folder where the git repo is stored, and perform push / commit:
That's how to connect via SSH to Heroku on Windows :)

Bitbucket/Github: permission denied public key

when I am trying to clone a rails app repo I have got permission to, I am getting this issue.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Even after adding public key by generating one, I am unable to solve this.
Although I am able to clone using he https method but after making changes, the same error comes while I try to push the code.
Please suggest an answer for this.
First, cd into your .ssh directory. Open up the terminal and run:
cd ~/.ssh && ssh-keygen
Second, you need to copy this to your clipboard:
cat id_rsa.pub | pbcopy # On OSX
cat id_rsa.pub | xclip # On Linux
Third, add your newly generated ssh key to your account via the github/bitbucket website (just paste there).
Next, setup your git config:
git config --global user.name 'your_user_name'
git config --global user.email 'your_email'
Finally, restart your command line to make sure the config is reloaded.
Now, you should be able to clone and push from/to your github repository.
For more information on this, see this github page or this bitbucket page.
When attempting to clone, push, or pull over SSH with Git, you may receive one of these messages if Bitbucket couldn't authenticate with the keys that your SSH agent offered.
Here are the most common reasons why you may see these messages:
You used sudo when attempting the connection
You shouldn't use sudo when cloning, pushing, or pulling because the ssh-agent runs on the user level, not the root level.
Your public key isn't loaded into Bitbucket
To check if your public key is loaded into Bitbucket, do the following:
From Bitbucket, choose Personal settings from your avatar in the lower left.
The Account settings page displays.
Click SSH keys.
The SSH keys page shows a list of any existing keys.
If you don't have any keys listed, you can follow our Set up an SSH key documentation to set one up.
Your key isn't loaded into your SSH agent
If your SSH agent doesn't know to offer Bitbucket a key, the connection fails. You may run into this issue if you've recently restarted your system.
You can refer to this Article for more informations:
https://support.atlassian.com/bitbucket-cloud/docs/troubleshoot-ssh-issues/
Check few things.
Is the generated new key is the one your ssh agent using when trying to ssh to server.
(Your ssh agent might be using a different key than the one you generated)
use this to list currently loaded keys by agent.
ssh-add -L
You properly added public key to your repository hosting location.
The keys corresponding to above 1 and 2 should match.
Please see this article: GitHub: Generating SSH Keys. What happens when you run:
ssh -T git#bitbucket.org
?
You may have added the wrong key to authenticate with.
I faced this error when I created another repository in my local. My ssh-keys were already set up and I was trying to push code through vs code.
The issue got resolved when I git push-ed through git bash like I was doing before.
For bit bucket I think I have tried everything with ssh. I have tried the answer from this stackoverflow question as well. But it doesn't work. So finally I just changed the clone command from SSH to HTTPS and it worked. Only then it asked for password for my account.

How to rectify SSH error: Heroku, in my Rails Application [duplicate]

I'm attempting to deploy my code to heroku with the following command line:
git push heroku master
but get the following error:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
I have already uploaded my public SSH key, but it still comes up with this error.
You have to upload your public key to Heroku:
heroku keys:add ~/.ssh/id_rsa.pub
If you don't have a public key, Heroku will prompt you to add one automatically which works seamlessly. Just use:
heroku keys:add
To clear all your previous keys do :
heroku keys:clear
To display all your existing keys do :
heroku keys
EDIT:
The above did not seem to work for me. I had messed around with the HOME environment variable and so SSH was searching for keys in the wrong directory.
To ensure that SSH checks for the key in the correct directory do :
ssh -vT git#heroku.com
Which will display the following ( Sample ) lines
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/Wrong/Directory/.ssh/identity type -1
debug1: identity file /c/Wrong/Directory/.ssh/id_rsa type -1
debug1: identity file /c/Wrong/Directory/.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/Wrong/Directory/.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/Wrong/Directory/.ssh/identity
debug1: Trying private key: /c/Wrong/Directory/.ssh/id_rsa
debug1: Trying private key: /c/Wrong/Directory/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
From the above you could observe that ssh looks for the keys in the /c/Wrong/Directory/.ssh directory which is not where we have the public keys that we just added to heroku ( using heroku keys:add ~/.ssh/id_rsa.pub ) ( Please note that in windows OS ~ refers to the HOME path which in win 7 / 8 is C:\Users\UserName )
To view your current home directory do : echo $HOME or echo %HOME% ( Windows )
To set your HOME directory correctly ( by correctly I mean the parent directory of .ssh directory, so that ssh could look for keys in the correct directory ) refer these links :
SO Answer on how to set Unix environment variable permanently
SO Question regarding ssh looking for keys in the wrong directory and a solution for the same.
I had the same issue, the steps below worked for me,
->heroku login
abc#gmail.com & password
->cd C:\Users\yourusername\.ssh (OR for cygwin shell ->cd ~/.ssh)
->ssh-keygen -t rsa -f id_rsa
if asks any passphrase don't use blank, fill with a passphrase,but not forget it.
After generating the key you need to add it, like so
$ ssh-add
and it to heroku
->heroku keys:add "id_rsa.pub"
change directory to workspace, than
->git clone git#heroku.com:stark-dawn-1234.git -o heroku
use passphrase that you set above.
Actually i also remove files below, but not sure that they are imp,
C:\Users\yourusername.heroku\credientals and C:\Users\yourusername.ssh\known_hosts
This problem was messing with me for a few days.
This might help.
1) Find out what keys you have in Heroku now.
$ heroku keys
=== 1 key for joe#example.com
ssh-dss AAAAB8NzaC...DVj3R4Ww== joe#workstation.local
2) Build a ~/.ssh/config file:
$ sudo vim ~/.ssh/config
Edit with this info
Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/ssh-dss # location and name of your private key
TCPKeepAlive yes
User joe#workstation.local
Here is the link that explains how to manage your ssh keys: https://devcenter.heroku.com/articles/keys#adding-keys-to-heroku
I had the same problem cause i had no public keys, so i did:
heroku keys:clear
heroku keys:add
That will generate a public key and then it works well
If you are a windows user the other solutions here probably won't solve your problem.
I use Windows 7 64-Bit + Git-1.7.7.1-preview20111027 and the solution was to copy my keys from C:\users\user\.ssh to C:\Program Files (x86)\Git\.ssh. That's where this git client looks for the keys when pushing to heroku.
I hope this helps.
This was the solution for me:
ssh-add ~/.ssh/my_heroku_key_rsa
To share my experience :
Git (my own install) was looking for the key named 'id_rsa'.
So I tried to rename my keys to 'id_rsa' and 'id_rsa.pub' and it worked.
Btw, I'm sure there is an other way to do it but I didn't look deeper yet.
If you've already uploaded the key then try to remove the key and then re-upload
it with a new key.
heroku keys:remove //removes the existing key
ssh-keygen -t rsa //generates a new key in ~/.ssh folder
heroku keys:add //uploads the new key, if no arguments r passed then the key generated
//in default directroy i.e., ~/.ssh/id_rsa is uploaded
git push heroku
this should work.
I killed myself for 3 days trying every possible combination to try to get this to work -- I finally tried making a DSA key instead and it worked.
Try DSA instead of RSA if it's not working for you.
(I'm using Ubuntu 11.10, ruby 1.8.7, heroku 2.15.1)
On Windows 7,64 bit,the above solution (Onur Turhan's) worked for me with slight changes as below
C:\Users\MyName > heroku login
Enter email/password
C:\Users\MyName >ssh-keygen -t rsa -f id_rsa
This generated two files(id_rsa and id_rsa.pub) in my c:\Users\MyName directory (Not in .ssh directory)
heroku keys:add id_rsa.pub
git clone git#heroku.com:some-heiku-xxxx.git -o heroku
I guess adding the correct "id_rsa.pub" file is the most important.After generating the public key using keygen just verify that you are adding correct key by looking at the time-stamp when it was created.
One single command works:
heroku keys:add
It will make one if it doesn't exist.
I had this problem when TortoiseGIT was installed on my machine. After changing the environment variable GIT_SSH from
"c:\Program Files\TortoiseGit\bin\TortoisePlink.exe"
to
"c:\Program Files (x86)\Git\bin\ssh.exe"
and following this tutorial with ssh-keygen and keys:add, it works!
Pushing was working for me and then stopped suddenly.
If the heroku api is experiencing downtime, you will get this error when you try to push.
Check:
https://status.heroku.com/
before freaking out too hard.
Sequence to follow
$ heroku login
$ ssh-keygen -t rsa
$ heroku keys:add
When executing second statement it would ask for input, just press Enter(return) three times and a key will be added.
The above given answer DOES work, but found out I needed to do some extra steps before it worked.
I removed all id_rsa* files and generated a new SSH using this guide.
Then, I destroyed the heroku app. Removed the ~/.heroku/credentials file.
'heroku create' command (and since the credentials file is removed, it will prompt you for your email/password.
FINALLY type 'heroku keys:add' and it will upload the default ~/.ssh/id_rsa.pub file.
It works! Well.... YMMV but I really do hope this can be some help as I struggled the whole day trying to figure this out! Haha
For all those who tried everything mentioned above on Windows 7 and still it didn't work, here is what I've done:
- open GitBash.exe from the Git directory C:\Program Files (x86)\Git\ (don't open a command prompt, this won't work).
- add the following as mentioned above, but you have to delete the #
Host heroku.com
Hostname heroku.com
Port 22
IdentitiesOnly yes
IdentityFile ~/.ssh/ssh-dss
TCPKeepAlive yes
User joe#workstation.local
now run git push heroku master and it should work.
It sounds like your ~/.ssh/authorized_keys file is not set up correctly. Verify that:
It is in the correct path.
The permissions of the file are 0600.
The permissions of ~/.ssh are 0700.
I had to do:
$ ssh-keygen -t rsa
$ heroku keys:add
Then it worked:
$ git push heroku master
Check your .ssh config for heroku. Go to the .ssh folder and open the config file
cd ~/.ssh
subl config
The 'subl' is for Sublime Text, but you can use whatever editor you wish. Look for the line "IdentityFile" and make sure it has the non public key listed:
IdentityFile "/Users/ircmullaney/.ssh/my_ssh"
not
IdentityFile "/Users/ircmullaney/.ssh/my_ssh.pub"
That did it for me. I'm not sure why mine had the public version in the config file, but it did and it was throwing the error:
Permissions 0644 for '/Users/ircmullaney/.ssh/my_ssh.pub' are too open.
I was still having problems after trying all of these ideas. This was my problem:
My remote heroku repository was funked. I refreshed it as follows:
git remote -v
Then remove the heroku one that is wrong:
git remote rm heroku
Then add the new one
git remote add heroku git#heroku.com:sitename.git
You can get the sitename from your Heroku settings page for your app. Good Luck!
The problem I faced was on Windows and invariably whenever I run the "heroku keys:add" it selected the github keys. So here are the steps I followed to resolve the issue
went to the .ssh directory under "Document and Settings" folder and deleted the git hub keys
run the command
heroku keys:add
The above command asked me to generate a new keys and following was the output
Could not find an existing public key.
Would you like to generate one? [Yn] Y
Generating new SSH public key.
Uploading SSH public key C:/Documents and Settings/Admin/.ssh/id_rsa.pub... done
! The 'heroku' gem has been deprecated and replaced with the Heroku Toolbelt, download and install from https://toolbelt.heroku.com.
rerun the command
heroku keys:add
The above command will not give the following output
Found existing public key: C:/Documents and Settings/Admin/.ssh/id_rsa.pub
Uploading SSH public key C:/Documents and Settings/Admin/.ssh/id_rsa.pub... done
Now use the git push heroku master
for me using the above steps solved the issue and was able to deploy the application on the cloud.
I was experiencing the same problem; following these steps should help:
First, log in: heroku login
Clear all keys: heroku keys:clear
Delete all files in local folder ( all .pub files and know_host) in .ssh/ folder
Log in again : heroku login - u will prompt with no key, so follow the onscreen instructions.
I would just to like to add that the directory is not necessarily C:\Users\[username]\.ssh. It is the directory in which you created your public key in.
For instance my home directory in Windows was changed to C:\[username]. Your home directory in a .ssh sub-folder is the best and most likely place you may have created your keys. You can check your home directory in Windows with the command:
echo %HOMEPATH%
If you want to use "sudo", example:
sudo git clone git#heroku.com......... -o heroku
you should also generate ssh key for your root user.
sudo su
cd /root/.ssh
ssh-keygen -t rsa
....
heroku keys:add id_rsa.pub
and it'll work.
if you don't use root user, generate ssh key in your user directory instead.
cd /home/user/.ssh
Sorry if my sentences messed up...
Try repairing permissions in Disk Utility (Mac OS X). Helped me
At first make sure hidden files are visible in your Mac.
If not do:
Open terminal and type in defaults write com.apple.Finder
AppleShowAllFiles TRUE
killall Finder
Next steps:
Going to Users/user_name/.ssh/ removed all the files.
Opening terminal type in ssh-keygen -t dsa
Then heroku keys:add ~/.ssh/id_dsa.pub
N.B. I did it in Mac OSX 10.7.2 Lion. Though the procedure should be same in others too.
I have this issue as well. I am using Mac OSX. The way I fixed that was to login as admin
sudo su
password
Solution of dmajkic help me at last:
For Windows users it may means: git client coudn’t find your keys.
Check keys in c:\Users\UserName.ssh\ and! environment variable HOME=c:\Users\UserName\
Here is what worked for me. The heroku site is not being added to your known hosts. Go to window-other- show view-git-git repositories. From there clone the repository. Once you clone it, delete the repository that was just created and then import it from the file menu. Do this since when you clone the repository, it does not add it to the explorer view. Now you should have the git repository and the explorer view.

Upload site on Heroku: Host key verification failed

The first time I unloaded a site on Heroku I faced many mistakes. How to correct?
k#k-Aspire-5750G:~/q$ git clone git#github.com:priroda/programmer-site
Cloning into 'programmer-site'...
The authenticity of host 'github.com (192.30.252.131)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
fatal: The remote end hung up unexpectedly
I have 2 files in directory ssh:
k#k-Aspire-5750G:~/.ssh$ ls
id_rsa id_rsa.pub
ssh
Your problem here looks like you're trying to ssh into heroku and clone your repo directly from github?
The problem here is that if you connect to github through ssh (a third party), you will basically have to create an authenticity token (ssh key), so that your third party machine is able to connect to your github repo
--
Fix
Typically, your local machine will be authenticated anyway when you install git, heroku not so. I would therefore recommend you push to Heroku from your local machine, rather than trying to clone through github:
$ git remote add heroku git#heroku.com
$ git add .
$ git commit -a -m "Heroku Deploy"
$ git push heroku master
If you do this first time, you will likely come back with some sort of request for your ssh to be accepted or something - just accept & it should push to Heroku from your local machine
Here is Heroku's take on the matter
Your output looks like a problem with your host verification with Github.com when you're trying to clone and nothing to do with Heroku.
Have a look in your ~/.ssh/known_hosts for a github.com entry and highlight it and remove it. Then try your clone again and it will prompt to verify, say yes and then it should clone successfully.

Resources