# Access device after deletion

**URL:** <https://forums.balena.io/t/access-device-after-deletion/154171>\
**Category:** Product support\
**Created:** [July 13, 2020, 8:57am UTC](https://forums.balena.io/t/access-device-after-deletion/154171 "2020-07-13T08:57:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bversluijs](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bversluijs/32/3954_2.png) [@bversluijs](https://forums.balena.io/u/bversluijs)\
**Post date:** [July 13, 2020, 8:57am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/1 "2020-07-13T08:57:58Z")

</div>

Hi all,

I have a device which is deleted from balenaCloud by a colleague (😅). It still has everything running on it, and I’d like to access it via SSH. It’s an UP Squared board with the UP image on it (balenaOS 2.29.2+rev1). I’ve tried to add an SSH key via the `config.json`. I’ve setup an Live USB of Ubuntu via that way, changed the `config.json`.

I’ve added the following on root level of the JSON:

```json
"os": {
  "sshKeys": [
    "ssh-rsa ..."
  ]
}

```

But when I try to SSH into it, it still says “permission denied (publickey)”. So it looks like the SSH key isn’t added.

Did I do something wrong, or is there any other way to access the device? I have to login into the running device, because I have to run a script on it for the very last time.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![vipulgupta2048](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@vipulgupta2048](https://forums.balena.io/u/vipulgupta2048)\
**Post date:** [July 13, 2020, 11:05am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/8 "2020-07-13T11:05:55Z")

</div>

Hello, are you running a production image?

---

<div class="post-metadata">

**Author:** ![bversluijs](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bversluijs/32/3954_2.png) [@bversluijs](https://forums.balena.io/u/bversluijs)\
**Post date:** [July 13, 2020, 11:35am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/9 "2020-07-13T11:35:52Z")

</div>

Yeah, unfortunately it is a production image…

---

<div class="post-metadata">

**Author:** ![vipulgupta2048](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@vipulgupta2048](https://forums.balena.io/u/vipulgupta2048)\
**Post date:** [July 13, 2020, 11:48am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/10 "2020-07-13T11:48:13Z")

</div>

If you have added custom ssh keys before provisioning the image, then you should still be able to SSH into the device to login even after deleting the device through standalone SSH, like:

`ssh -p 22222 -i ~/.ssh/id_rsa root@<ip>`

---

<div class="post-metadata">

**Author:** ![vipulgupta2048](https://avatars.discourse-cdn.com/v4/letter/v/a183cd/32.png) [@vipulgupta2048](https://forums.balena.io/u/vipulgupta2048)\
**Post date:** [July 13, 2020, 11:51am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/11 "2020-07-13T11:51:00Z")

</div>

Also, can you provide more information into how you are adding SSH keys and editing `config.json`even after deleting the device.

---

<div class="post-metadata">

**Author:** ![bversluijs](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bversluijs/32/3954_2.png) [@bversluijs](https://forums.balena.io/u/bversluijs)\
**Post date:** [July 13, 2020, 12:21pm UTC](https://forums.balena.io/t/access-device-after-deletion/154171/12 "2020-07-13T12:21:04Z")

</div>

Hi,

Thanks for your help!  
I have a Live USB of Ubuntu, and use the ‘Try without installing’ option.  
Then, I mount the `resin-boot` and change the `config.json` inside that partition.  
After saving the file, I reboot the UP Squared and remove the Live USB, so it starts Balena.

But I still get the permission denied when SSH’ing into it, using the correct SSH key.

---

<div class="post-metadata">

**Author:** ![dfunckt](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dfunckt/32/56_2.png) [@dfunckt](https://forums.balena.io/u/dfunckt)\
**Post date:** [July 14, 2020, 7:31am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/16 "2020-07-14T07:31:09Z")

</div>

That should work but manually editing the config.json is a bit error-prone, so to rule out any such errors can you please do it this way:

```auto
cat /mnt/boot/config.json | jq . > /mnt/boot/config.json.new
vi /mnt/boot/config.json.new
(edit file)
cat /mnt/boot/config.json.new | jq .
(verify file is parseable)
cat /mnt/boot/config.json.new | jq . > /mnt/boot/config.json

```

---

<div class="post-metadata">

**Author:** ![bversluijs](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bversluijs/32/3954_2.png) [@bversluijs](https://forums.balena.io/u/bversluijs)\
**Post date:** [July 14, 2020, 11:24am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/19 "2020-07-14T11:24:27Z")

</div>

I’m going to try that tomorrow. However, I’ve copied the JSON to my IDE when trying this, and added the SSH keys there and minified it again. It also checks if the JSON is valid, which it was. So probably the JSON is valid.

But it’s correct that I should change the `config.json` in the `resin-boot` partition, and not anywhere else?

---

<div class="post-metadata">

**Author:** ![lucianbuzzo](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/lucianbuzzo/32/615_2.png) [@lucianbuzzo](https://forums.balena.io/u/lucianbuzzo)\
**Post date:** [July 14, 2020, 11:43am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/20 "2020-07-14T11:43:43Z")

</div>

Yes that’s correct, you only need to change the `config.json` file in the `resin-boot` partition (this partition is mounted at `/mnt/boot/`).

---

<div class="post-metadata">

**Author:** ![bversluijs](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bversluijs/32/3954_2.png) [@bversluijs](https://forums.balena.io/u/bversluijs)\
**Post date:** [July 15, 2020, 8:36am UTC](https://forums.balena.io/t/access-device-after-deletion/154171/22 "2020-07-15T08:36:33Z")

</div>

Hi,

It still doesn’t work, so maybe you guys can spot the problem. This is my `config.json` at `/resin-boot/config.json` (with some things left out):

```json
{
  "apiEndpoint": "https://api.balena-cloud.com",
  "appUpdatePollInterval": "900000",
  "applicationId": "<app-id>",
  "applicationName": "<app-name>",
  "deltaEndpoint": "https://delta.balena-cloud.com",
  "deviceApiKey": "<api-key>",
  "deviceApiKeys": {
    "api.balena-cloud.com": "<api-key>"
  },
  "deviceId": "<device-id>",
  "deviceType": "up-board",
  "listenPort": "48484",
  "mixpanelToken": "<token>",
  "pubnubPublishKey": "",
  "pubnubSubscribeKey": "",
  "registered_at": "1575315785",
  "registryEndpoint": "registry2.balena-cloud.com",
  "userId": "<user-id>",
  "username": "<user-name>",
  "uuid": "<uuid>",
  "vpnEndpoint": "vpn.balena-cloud.com",
  "vpnPort": "443",
  "persistentLogging": "true",
  "os": {
    "sshKeys": [
      "ssh-rsa AAAAB3NzaC1yc2EAAAA...."
    ]
  }
}

```

I can’t figure out what’s wrong and why it keeps declining my SSH key…

---

<div class="post-metadata">

**Author:** ![JuanFRidano](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/juanfridano/32/3934_2.png) [@JuanFRidano](https://forums.balena.io/u/JuanFRidano)\
**Post date:** [July 15, 2020, 2:26pm UTC](https://forums.balena.io/t/access-device-after-deletion/154171/25 "2020-07-15T14:26:49Z")

</div>

Hi,  
your `config.json` file looks fine, I have just tried it myself and I have to say, I had to be very careful because the text editor I was using to copy the key wants to reformat the string (line breaks).

also **make sure you are copying the complete public ssh-key** , in my case it was:  
` "os": { "sshKeys": ["ssh-rsa ######## me@email.com"] }`  
after that `balena ssh <Device's IP Address> `

I would say it may be a problem on how the Key is getting copied, or that your local machine is not using the exact same key. I hope this helps, please get back to us if it doesn’t

Best,

Juan
