Multiple Heroku Accounts
- By Jessica Lord
- heroku, web dev
I finally actually sat down to tackle my multiple Heroku accounts problem. I started by following Chris's comment and using a plugin. Something went awry, probably my fault, but I eneded up uninstalling it (which turns out to be a pain) and figuring out how to do what it does manually.
Create new keys for accounts
First, create new keys for each of the accounts you’re setting up. For me that’s a work account and personal account.
ssh-keygen -t rsa -C "email@example.com"
When it asks what to name it, give it a name that's easy to recall, like identity.heroku.work.
Configure your system .ssh
Next, you have to edit your
.ssh/config file and set up new hosts. If you use Textmate, you can type
mate ~/.ssh/config in terminal. Add these lines, changing out the work/personal and IdentityFile to match your needs/keys.
Host heroku.work HostName heroku.com IdentityFile ~/.ssh/identity.heroku.work IdentitiesOnly yes Host heroku.personal HostName heroku.com IdentityFile ~/.ssh/identity.heroku.personal IdentitiesOnly yes
Configure your git repo
Now edit the
.git/config files. Inside of your root directory for the repo, type
mate .git/config to open the file. It will look something like this, but under
[remote "heroku"] you will change the url from heroku.com to heroku.work (or whatever you're calling your different accounts).
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true [branch "master"] [remote "heroku"] url = firstname.lastname@example.org:splost.git fetch = +refs/heads/*:refs/remotes/heroku/* [remote "origin"] url = email@example.com:jllord/splost-heroku.git fetch = +refs/heads/*:refs/remotes/origin/*
Tell Heroku which keys to use
In Terminal, navigate to the root directory for the repo and
heroku login to the account associated with that repo. You'll need to tell heroku what key to use with that account.
heroku keys:add ~/.ssh/identity.heroku.work.pub
Repeat for other repos you have associated with that account. Then navigate to the root of a repo with a different account, make sure to now
heroku login with your other account login information. Repeat the steps for adding the keys to this account (only add the other account, ie, identity.heroku.personal).
So many keys, so much fun. If you are like me and had made a hot mess of keys, it may be useful to list your keys (in heroku and on your computer), see what's going on and clean up. Now I have one key that github uses and two keys for my two Heroku accounts and things are running much more smoothly.