Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't understand ssh system in Heroku

Tags:

ssh

heroku

I can't get the system of managing ssh keys.

I want to push application to Heroku, so I tried to push but get error.

Here is my log

    $ git push heroku master
  !  Your key with fingerprint bf:f6:ed:14:9d:cd:52:a2:a3:16:b2:e9:b4:f2:bf:ba is not authorized to access warm-samurai-6574.
  fatal: The remote end hung up unexpectedly
  User@PK /e/examples (master)
  $ heroku keys:add
  Found existing public key: C:/Users/User/.ssh/id_rsa.pub
  Uploading SSH public key C:/Users/User/.ssh/id_rsa.pub
  !This key is already in use by another account. Each account must have a unique key.
  User@PK /e/examples (master)
  $ heroku keys
  === 1 key for [email protected]
  ssh-rsa AAAAB3NzaC...etyxYh4Q== User@PK

Every account has own ssh key. So I can push from any computer, because ssh key is pushing to heroku ?

Every application on heroku should have own ssh key or not ?

like image 736
deny7ko Avatar asked Jul 06 '12 07:07

deny7ko


3 Answers

Your computer has an SSH key, but that SSH key is associated with another Heroku account. If you need to use both accounts for different applications on the same computer you should make a new SSH key on your machine and upload it to Heroku:

$ ssh-keygen

Make sure to save it as '/Users/User/.ssh/new_id_rsa.pub' when the prompt asks you.

$ heroku keys:add /Users/User/.ssh/new_id_rsa.pub 

You then need to add another host to your ~/.ssh/config:

Host heroku-alt
HostName heroku.com
IdentityFile ~/.ssh/new_id_rsa

And then update the .git/config in your project to use the host alias:

[remote "heroku"]
  url = git@heroku-alt:myapp.git
  fetch = +refs/heads/*:refs/remotes/heroku/*

By choosing between heroku and heroku-alt in the remote of the .git/config files of specific projects you can manage which projects use which credentials.

like image 191
Daniel X Moore Avatar answered Oct 21 '22 15:10

Daniel X Moore


Basically, your computer has an SSH key. However, the SSH key on it is associated with another Heroku account (different from the one you are using now). Your best bet would be to generate a brand new SSH key and add it to Heroku.

Just make a new SSH key on your machine and upload it to Heroku:

$ ssh-keygen

Make sure to save it as '/Users/User/.ssh/new_id_rsa.pub' when the prompt asks you.

$ heroku keys:add /Users/User/.ssh/new_id_rsa.pub 

This should allow you to use Heroku.

As for your other questions: you can push to Heroku from any computer as long as you add the computer's SSH keys through heroku keys:add. And no, every application does not need to have it's own SSH key.

like image 40
Danish M. Avatar answered Oct 21 '22 15:10

Danish M.


Heroku requires an SSH key to be unique to an account. Two accounts cannot have the same ssh key.

You can do ONE of these to solve your issue:

  • Unlink the ssh key from the other heroku account. Chances are you are not using that account. This is path of least resistance.
  • Delete the existing keys. Generate a new ssh public/private key pair. Advantage is you will retain the default name for keys and thus it will be automatically found by any application you use.
  • Generate a new ssh public/private key pair and save it alongside your existing keys. The disadvantage is, these two keys will have a custom name. If you end up using these keys often, you will need to locally set configure ssh to use these instead of the default id_rsa. This does require some work and might get involved.

Which you choose really depends on you.

If you choose the third option, refer this answer https://superuser.com/a/272613/25665 for how to configure ssh locally to always use the new keys for heroku. In case you are wondering why bother with this, well, you will be interacting with heroku by pushing to a git repository. That requires you to be authenticated using ssh. By default it will use the older keys and you wont be able to push. Its just easier to instead tell ssh to use the alternate key when interacting with warm-samurai-6574.heroku.com

The following link has instructions on creating a new key. You will need to either accept the default names or give custom ones depending on which option you chose. https://devcenter.heroku.com/articles/keys

Can you push from any computer?

Again, it depends. If the computer has your ssh keys and its configured to use your keys for the heroku domain, then yes. You can instead choose to not copy your keys there and simply add the ssh keys present there to your heroku account.

Does each app require a unique key?

No. You can have multiple apps under one heroku account. They all will share the keys you upload to your heroku account.

like image 20
Amith George Avatar answered Oct 21 '22 16:10

Amith George