How to keep Heroku CLI logged in
I use the heroku command-line most days. It frequently logs out, giving this message:
▸ Invalid credentials provided.
Here’s how to keep the heroku CLI logged in for a year.
- Log in to Heroku’s dashboard and create a new Authorization
- Call it something useful e.g.
2025-01-23 heroku cli desktop
to remind you next time. - Set Expires after to
31536000
(1 year) Copy that new token into your
~/.netrc
file# ~/.netrc # Regenerate Heroku Authorization annually with a 1-year expiry (31536000 seconds). See: # * https://dashboard.heroku.com/account/applications # * https://paul.fawkesley.com/blog/2025-01-23-how-to-keep-heroku-cli-logged-in/ machine api.heroku.com login your.heroku.login@example.com password HRKU-YOUR-NEW-TOKEN machine git.heroku.com login your.heroku.login@example.com password HRKU-YOUR-NEW-TOKEN
That’s it. Test it by running heroku whoami
.
Notes:
- I tried logging in with
heroku login -i
using the new token as the password. This appeared to work but created another short-lived Authorization in Heroku. Thanks to this Stackoverflow answer. - Don’t make a token that never expires. I don’t want a backup I create now to be able to compromise my account 10 years from now. Forever tokens are bad.
Thoughts? Get in touch