Heroku workshop - Java

Authenticating with Heroku

To deploy your source code onto Heroku you need to first authenticate yourself (prove you are who you say you are). You only need to authenticate yourself once for each computer you use to connect to Heroku.

Authentication via HTTP Git service (new)

Heroku has released a new service called Http Git which removes the need for a public key and enables those users who would otherwise be stuck behind restrictive firewalls.

To authenticate yourself to heroku, open a command line terminal and enter the following command:

heroku login

Provide your Heroku username and password when prompted. If your account has 2-factor authentication configured, you will also be prompted for a 2-factor code.

Heroku authentication

If this command is successful, your Heroku API key is added to the ~/.netrc file. When you run other Heroku Toolbelt commands or push code, this API key is used to authenticate you.

Heroku Http Git entry in .netrc

For more information, see the article Http Git.

You can now move on to the next section.

Alternative authentication method by Public Key (optional)

You can also authenticate yourself with Heroku via public key encryption. To do so you need to add an SSH key to your Heroku account. This same approach taken by services such as Github, however its much easier to add your key with the Heroku toolbelt.

If you have an existing SSH key, use the following command

heroku keys:add

To use your SSH key with your heroku apps, you need to specify the --ssh-git option on the heroku create command

heroku create --ssh-git my-app

You can configure Git to always use SSH when pushing to Heroku no mater how the app was create using the command git config --global url.ssh://git@heroku.com/.insteadOf https://git.heroku.com/. More information is in the Deploying with Git article.

Creating your own key (optional)

If you do not have an SSH key, you can create one using the ssh-keygen command. When you create the public key, ensure you add the email address of your Heroku account as a comment:

ssh-keygen -t rsa -C "email@used-for-heroku-account.com"

You can then add a new key to Heroku using the following command:

heroku keys:add

If you have only one public key, this command will just add it to heroku without prompting. If you have more than one pubic key then heroku will prompt you as to which key you want to add.

For more information, see the Managing SSH Keys article on Heroku document center.