As a developer you may need to push multiple apps to multiple heroku accounts. Having multiple Heroku accounts and using multiple Heroku accounts from one machine is no fun. Before I start talking about the topic for this post which is having multiple accounts on Heroku, I would like to mention that I have been working on heroku for quite some time now and it will not be wrong if I say that I have really enjoyed exploring Heroku. My love for Heroku increased even more when I successfully deployed a java application on heroku and see it go live on internet….
I have created multiple Heroku accounts. The problem is that the heroku toolbelt authentification is based on ssh certificates. Therefore everything was fine until I really messed up with the ssh keys…
By default the vanilla Heroku toolset can only work with a single Heroku account. When you first create an account on Heroku and login from the Heroku gem or toolbelt, it associates your SSH key with your account. This SSH key is tied to our account, so we can have one Heroku account per SSH key.
Before getting into the issues that arise when you mess up with the ssh keys of your heroku accounts let us look what do you really need to do if you want to access multiple heroku account from your machine?
Fortunately someone has created heroku-accounts to manage this for you.
Heroku Accounts is a plugin for Heroku written by @ddollar that manages multiple accounts for you.
So the first step will be to install Heroku –Accounts plugin(I am assuming that you already have either the Heroku gem or Heroku toolbelt installed.)
To install this plugin run the following command:
$ heroku plugins:install git://github.com/ddollar/heroku-accounts.git
Next, you need to setup your personal account and client account(s).
You can add accounts in either fully automated mode or by making manual configurations.
For fully automated mode run the following command:
heroku accounts:add [account_name] –auto
Replace [account_name] with any name that’s meaningful to you, the name is only used locally.
e.g- $ heroku accounts:add personal –auto
As soon as you run the above command you will be asked to enter your Heroku credentials.
On successful entry of your credential what this does is automatically create a new SSH key and store in identity.heroku.personal, create a heroku.personal host record in your ~/.ssh/config that would use the correct key and uploads your public key identity.heroku.personal.pub to your Heroku account.
But if you want to manually configure the ssh key path in ~/.ssh/config file then you need run the following command to add the account:
$ heroku accounts:add personal
As soon as you run the above command following message will appear on your screen:
Host heroku.personal
HostName heroku.com
IdentityFile /PATH/TO/PRIVATE/KEY
IdentitiesOnly yes
I advice everyone to find out in details about this plugin on the following link: https://github.com/ddollar/heroku-accounts
Besides that there is something to note when you use multiple accounts on Heroku:
So far so good…. But sometimes using multiple accounts on heroku may land us in trouble. But trust me this happens only when we have really messed up with our ssh keys.
I ran into trouble when mistakenly I used one account to initialize the Git and another to push the changes. Obviously this created issues with my public key and I got error similar to below:
! Your key with fingerprint 2c:4e:7b:df:02:7e:18:c8:2a:16:04:bc:55:5a:87:97
is not authorized to access reviews.
fatal: The remote end hung up unexpectedly
Therefore you need to ensure that you are using the correct ssh key.
If you get similar error then first make sure that you are pushing to the right heroku account. You may also check that the ssh key of the Heroku account matches with the one on your machine or not. In case your ssh key is not present in your heroku account, use heroku keys:add command to add your machines existing ssh key(or generate a new one if not exists) to heroku account .For more detailed steps please refer https://devcenter.heroku.com/articles/keys.
One more point that I would like to mention here is that If you are using multiple accounts and you want to clone your source code from Heroku then you have to make a minor change in the url of the repository.
To clone a git repository from Heroku, change 'heroku.com' to the Host of the desired account defined in your .ssh/config:
e.g - $ git clone [email protected]:repository.git
instead of $ git clone [email protected]:repository.git
Similarly when you try to push your code to heroku check .git/config file , change the substring in the url from ‘heroku.com' to the Host of the desired account defined in your .ssh/config specified in this file. Therefore your url will look something like below:
url = [email protected]:my-app-name.git
.
I have created multiple Heroku accounts. The problem is that the heroku toolbelt authentification is based on ssh certificates. Therefore everything was fine until I really messed up with the ssh keys…
By default the vanilla Heroku toolset can only work with a single Heroku account. When you first create an account on Heroku and login from the Heroku gem or toolbelt, it associates your SSH key with your account. This SSH key is tied to our account, so we can have one Heroku account per SSH key.
Before getting into the issues that arise when you mess up with the ssh keys of your heroku accounts let us look what do you really need to do if you want to access multiple heroku account from your machine?
Fortunately someone has created heroku-accounts to manage this for you.
Heroku Accounts is a plugin for Heroku written by @ddollar that manages multiple accounts for you.
So the first step will be to install Heroku –Accounts plugin(I am assuming that you already have either the Heroku gem or Heroku toolbelt installed.)
To install this plugin run the following command:
$ heroku plugins:install git://github.com/ddollar/heroku-accounts.git
Next, you need to setup your personal account and client account(s).
You can add accounts in either fully automated mode or by making manual configurations.
For fully automated mode run the following command:
heroku accounts:add [account_name] –auto
Replace [account_name] with any name that’s meaningful to you, the name is only used locally.
e.g- $ heroku accounts:add personal –auto
As soon as you run the above command you will be asked to enter your Heroku credentials.
On successful entry of your credential what this does is automatically create a new SSH key and store in identity.heroku.personal, create a heroku.personal host record in your ~/.ssh/config that would use the correct key and uploads your public key identity.heroku.personal.pub to your Heroku account.
But if you want to manually configure the ssh key path in ~/.ssh/config file then you need run the following command to add the account:
$ heroku accounts:add personal
As soon as you run the above command following message will appear on your screen:
Host heroku.personal
HostName heroku.com
IdentityFile /PATH/TO/PRIVATE/KEY
IdentitiesOnly yes
I advice everyone to find out in details about this plugin on the following link: https://github.com/ddollar/heroku-accounts
Besides that there is something to note when you use multiple accounts on Heroku:
So far so good…. But sometimes using multiple accounts on heroku may land us in trouble. But trust me this happens only when we have really messed up with our ssh keys.
I ran into trouble when mistakenly I used one account to initialize the Git and another to push the changes. Obviously this created issues with my public key and I got error similar to below:
! Your key with fingerprint 2c:4e:7b:df:02:7e:18:c8:2a:16:04:bc:55:5a:87:97
is not authorized to access reviews.
fatal: The remote end hung up unexpectedly
Therefore you need to ensure that you are using the correct ssh key.
If you get similar error then first make sure that you are pushing to the right heroku account. You may also check that the ssh key of the Heroku account matches with the one on your machine or not. In case your ssh key is not present in your heroku account, use heroku keys:add command to add your machines existing ssh key(or generate a new one if not exists) to heroku account .For more detailed steps please refer https://devcenter.heroku.com/articles/keys.
One more point that I would like to mention here is that If you are using multiple accounts and you want to clone your source code from Heroku then you have to make a minor change in the url of the repository.
To clone a git repository from Heroku, change 'heroku.com' to the Host of the desired account defined in your .ssh/config:
e.g - $ git clone [email protected]:repository.git
instead of $ git clone [email protected]:repository.git
Similarly when you try to push your code to heroku check .git/config file , change the substring in the url from ‘heroku.com' to the Host of the desired account defined in your .ssh/config specified in this file. Therefore your url will look something like below:
url = [email protected]:my-app-name.git
.