Software⏱️ 2 min read📅 2026-05-30

How to Fix: Permission denied (publickey) when deploying heroku code. fatal: The remote end hung up unexpectedly

Heroku deployment issue with public key error.

Quick Answer: Check if the public key is correctly configured in Heroku, ensure it's not expired or revoked.

The error message 'Permission denied (publickey). fatal: The remote end hung up unexpectedly' occurs when the Heroku Git repository is unable to authenticate your SSH connection. This issue can arise even if you have already uploaded your public SSH key, as in your case.

🛑 Root Causes of the Error

  • Incorrectly formatted public SSH key in your Git repository.
  • Public SSH key not correctly linked to your Heroku account.
  • Incompatible SSH client version with the one used by Heroku.

🛠️ Step-by-Step Verified Fixes

Method 1: Verifying SSH Key Format

  1. Step 1: Check your public SSH key for any typos or formatting issues.
  2. Step 2: Use the `ssh -T` command to test if the key is correctly formatted and linked to your Heroku account.

Method 2: Re-linking SSH Key

  1. Step 1: Log in to your Heroku account and navigate to the 'Settings' page.
  2. Step 2: Click on 'SSH keys' under the 'Security' section, then click 'Add SSH key'.
  3. Step 3: Copy and paste your public SSH key into the input field, making sure to remove any leading or trailing whitespace.

✨ Wrapping Up

To resolve this issue, you can try the above methods. If none of them work, consider reaching out to Heroku support for further assistance.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions