Today I run into some trouble when I tried to access another Heroku account from my computer. After some research, I discovered the heroku-accounts plugin, which completely solved my problem! 🙂
Let’s see how it works…
The pluguin heroku-accounts manages multiple Heroku accounts for you. Assuming you have the Heroku toolbelt installed, you can install this pluguin with the command:
$ heroku plugins:install https://github.com/heroku/heroku-accounts.git
Then, you can configure each of your accounts. Let us start with an account named work:
$ heroku accounts:add work --auto
and then, you’ll have to enter the corresponding Heroku credentials. This creates a new private Key.
As indicated by the message on your terminal, in the file ~/.ssh/config you will see the following:
Host heroku.work  HostName heroku.com  IdentityFile /PATH/TO/PRIVATE/KEY  IdentitiesOnly yes
Finally, to be able to push correctly our app to Heroku, we also need to change the Git configuration. In the .git folder of our app, edit or create a file named config and change the substring in the url from heroku.com to heroku.work, where we wrote the name of our account. Therefore, the final url in that file is:
[remote "heroku"] Â Â Â url = git@heroku.work:name-of-you-app.git
In a similar way, you can create another account, which we call personal:
$ heroku accounts:add personal --auto
We can list the accounts we have defined by:
$ heroku accounts
which returns
personal work
Finally, once we have our accounts set we can move from one account to the other with:
$ heroku accounts:set work $ heroku accounts:set personal
However, we need to be in the directory where exists the .git file to do this.
If you want to know which account is active, list the accounts and an * will appear on your active account. For example, if you have the personal account active:
$ heroku accounts * personal work
Hope it was useful! 🙂
Marina Mele has experience in artificial intelligence implementation and has led tech teams for over a decade. On her personal blog (marinamele.com), she writes about personal growth, family values, AI, and other topics she’s passionate about. Marina also publishes a weekly AI newsletter featuring the latest advancements and innovations in the field (marinamele.substack.com)