Key is invalid. You must supply a key in OpenSSH public key format Github

Ahmadreza Shamimi
3 min readJun 24, 2023

--

“It seems like you’re trying to add an OpenSSH public key to your GitHub account, but you’re encountering an error stating “Key is invalid. You must supply a key in OpenSSH public key format”. Here are a few things you could check”

I had this issue and #CHATGPT help me to fix it !

How?I will show you …

  1. Format of the key: The key should begin with ssh-rsa, ssh-ed25519, ecdsa-sha2-nistp256, ssh-dss and followed by a space, and then the rest of the key. An example would be ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAA....
  2. Spaces: Ensure there are no spaces in your key except the one following the key type (ssh-rsa, ssh-ed25519, etc). The key should be one continuous line of characters.
  3. Correct Key: Make sure you’re adding the correct public key file, not the private one. The public key usually has a .pub extension (for example, id_rsa.pub).
  4. Existing Key: If you’re adding a key that’s already been added to another GitHub account, you’ll get an error. Each key should be unique to an account.

Here’s how you can generate a new SSH key in OpenSSH format:

Open Terminal and paste the text below, substituting in your GitHub email address:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

This creates a new ssh key, using the provided email as a label.

> Generating public/private rsa key pair.

When you’re prompted to “Enter a file in which to save the key,” press Enter. This accepts the default file location.

> Enter a file in which to save the key (/home/you/.ssh/id_rsa): [Press enter]

At the prompt, type a secure passphrase or leave it empty if you don’t want to use a passphrase.

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

Once you have a key generated, you can add it to your GitHub account by:

  1. Copy the SSH public key to your clipboard. If your SSH public key file has a different name than the example code, modify the filename to match your current setup. If copying the content of the file, ensure you copy the entire key starting with ssh-rsa and ending with your email address. You can display the content of the key file with cat ~/.ssh/id_rsa.pub and then copy it.
  2. In the upper-right corner of any page in GitHub, click your profile photo, then click Settings.
  3. In the user settings sidebar, click SSH and GPG keys.
  4. Click New SSH key or Add SSH key.
  5. In the “Title” field, add a descriptive label for the new key. For example, if you’re using a personal Mac, you might call this key “Personal MacBook Air”.
  6. Paste your key into the “Key” field.
  7. Click Add SSH key.

For checking the id_rsa key and copy open termial and write this command :

 vi ~/.ssh/id_rsa.pub

Goodluck

--

--

Ahmadreza Shamimi

I'm Ahmadreza Shamimi with an experienced with over 10 years of experience coding with web and mobile platforms.