May 16, 2017

Managing keys for pushing to multiple heroku accounts

For convenience when you manage multiple applications from multiple Heroku accounts, so you won’t have to login on the terminal to switch between multiple accounts whenever you have to make deployments.

I had a challenge with pushing to another heroku account from my command line...

These are the steps I took to fix the error (redacted) below:

 !  Your account xxx@gmail.com does not have access to xx-heroku-app.
 !
 !  SSH Key Fingerprint: xx:xx:xx...

fatal: Could not read from remote repository.

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

Create a new ssh key doc, you can customize the pub filename for the different keys.

Add new key to the machine: ssh-add ~/.ssh/id_rsa_myherokuapp

Install heroku accounts setup multiple accounts and login

Modify ~/.ssh/config and add different alternate hosts for heroku.com to your ~/.ssh/config for each heroku accounts e.g.

Host heroku.myherokuapp
  HostName heroku.com
  IdentityFile ~/.ssh/id_rsa_myherokuapp
  IdentitiesOnly yes

Login to the right heroku account and add the newly created key using heroku keys:add

To view all the heroku accounts you have setup, run heroku accounts

To find out the current heroku account you're logged into, run heroku accounts:current

To switch to the desired heroku accounts, run heroku accounts:set name_of_account