# Unable to add SSH key

**URL:** <https://forums.balena.io/t/unable-to-add-ssh-key/350024>\
**Category:** Product support\
**Tags:** ssh, balena-cli\
**Created:** [November 9, 2021, 4:25pm UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024 "2021-11-09T16:25:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdickson](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@tdickson](https://forums.balena.io/u/tdickson)\
**Post date:** [November 9, 2021, 4:25pm UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/1 "2021-11-09T16:25:56Z")

</div>

Hi there. Need a bit of direction. Trying to allow for ssh connection via the Balena CLI. documentation doe snot provide how to create key. I have created keys, but get a error stating:

"should match pattern “^(ssh-rsa|ssh-dss|ssh-ed25519|ecdsa-sha2-nistp256|ecdsa-sha2-nistp384|ecdsa-sha2-nistp521) [A-Za-z0-9+/=]+( [^]+)\*$”

No idea what i’m doing wrong. using Puttykeygen. Could really use a well explained process starting with how to create a key, where to store it locally and then how to add it to the keys under preferences. Thanks.

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [November 10, 2021, 8:19am UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/2 "2021-11-10T08:19:04Z")

</div>

Hi,

It is expecting your public key in the format used by OpenSSH, rather than PuTTY (SSH2 format).  
You should be able to convert it, using `ssh-keygen -i -f <ssh2 keyfile>.pub`

You may also need to convert your key to OpenSSH (in puttygen: Conversions \> Export OpenSSH) before exporting your public key.  
I’m not 100% sure balena-cli accepts PuTTY keys. (believe its default behavior is to wrap openssh, which doesn’t)

---

<div class="post-metadata">

**Author:** ![tdickson](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@tdickson](https://forums.balena.io/u/tdickson)\
**Post date:** [November 10, 2021, 1:24pm UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/3 "2021-11-10T13:24:22Z")

</div>

Thanks @TJvV!!! That seems to have worked.

---

<div class="post-metadata">

**Author:** ![dtischler](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dtischler/32/2483_2.png) [@dtischler](https://forums.balena.io/u/dtischler)\
**Post date:** [November 12, 2021, 12:14am UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/4 "2021-11-12T00:14:13Z")

</div>

Thanks for the assist @TJvV !

---

<div class="post-metadata">

**Author:** ![shadababe04](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shadababe04/32/7838_2.png) [@shadababe04](https://forums.balena.io/u/shadababe04)\
**Post date:** [April 10, 2022, 7:52am UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/6 "2022-04-10T07:52:25Z")

</div>

> [@TJvV](#):
>
> ssh-keygen -i -f .pub

i try to do the same got error: do\_convert\_from\_ssh2: base64 decoding failed: invalid format

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [April 11, 2022, 8:20am UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/7 "2022-04-11T08:20:46Z")

</div>

Hi,

It sounds to me like you might be trying to convert a wrong type of key.  
This is the same error you get when trying to convert a key that’s already in the right format.  
Which format does your public key have?

If it already looks something like `ssh-rsa single-line-base64-key-string comment`, you don’t need to convert it.  
Only when it looks like

```auto
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "comment"
multi-line
base64-string
here
---- END SSH2 PUBLIC KEY ----

```

Do you need to convert it.

---

<div class="post-metadata">

**Author:** ![dtcsight](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dtcsight](https://forums.balena.io/u/dtcsight)\
**Post date:** [November 9, 2022, 10:54pm UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/8 "2022-11-09T22:54:35Z")

</div>

hmm, I just experienced an issue with ssh rsa keys today. One of my devices is still using that old key but it no longer worked. If I try to delete and re-add the key, it complains about a pattern not matching. I had to update that to ed25519 instead.

Either rsa is no longer supported or there is a bug with the rsa key at the moment.

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [November 15, 2022, 8:20am UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/9 "2022-11-15T08:20:52Z")

</div>

Hi,

Can you maybe make a new thread for this issue?  
Makes it easier to keep track of things that are solved and not.

---

<div class="post-metadata">

**Author:** ![dtcsight](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@dtcsight](https://forums.balena.io/u/dtcsight)\
**Post date:** [November 19, 2022, 5:37pm UTC](https://forums.balena.io/t/unable-to-add-ssh-key/350024/10 "2022-11-19T17:37:59Z")

</div>

Done. [ssh-rsa keys broke](https://forums.balena.io/t/ssh-rsa-keys-broke/365480)
