# How to Preauthorize the device

**URL:** <https://hub.mender.io/t/how-to-preauthorize-the-device/2235>\
**Category:** General Discussions\
**Created:** [July 27, 2020, 5:21am UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235 "2020-07-27T05:21:58Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![alfrunes](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/alfrunes/32/703_2.png) [@alfrunes](https://hub.mender.io/u/alfrunes)\
**Post date:** [July 27, 2020, 12:32pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/22 "2020-07-27T12:32:26Z")

</div>

The parameters to `mender setup` has little to do with this issue as long as it connects to the server you’re fine.  
The log message shows that the device is not authorized (hence the pending device you observe). This can only mean one thing: the parameters passed to the pre-authorization request (either the `pubkey` or `identity_data` does not match that of the device).  
The device you see in the Preauthorized tab is only a provisional device, as long as no device connects with the given public key / identity data, the authentication set will remain in this state.  
You need to make sure you have the correct identity data and public key in the preauth request, if you get an error from the server saying the device already exists (even if its status is pending), then you need to decommission the device before you issue another preauth request.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 12:53pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/23 "2020-07-27T12:53:58Z")

</div>

Right now I have decommisioned the device.

1. I re-ran the entire POST Preauth request, Public key is same,. identity data is just this:  
(Just like doc mentioned , there was no output)  
preauth\_dev = json.dumps({  
“identity\_data”: {  
“mac”: “b8:27:eb:b4:b5:d2”,  
},  
.How do I make sure this is the only parameter needed for identity\_data??

2. Then I did, sudo systemctl start mender-client.service. but in logs its:

msg=“Authorize failed: transient error: authorization request failed: (request\_id: ): authentication request rejected server error message: dev auth: unauthorized”

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 1:03pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/24 "2020-07-27T13:03:24Z")

</div>

this is how I have given:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/cb0589c10c0c783758aa30cb01a39c3b0f2bdb02.png)

And this is whats happening, In the preauthorized tab, it shows pending and then In the status log that above error:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/1X/0f5b0b4b0bb08a2f034b87b16850f5de4218c4d9.png)

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 1:26pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/25 "2020-07-27T13:26:26Z")

</div>

So, I ran the Pre-Auth request and the device is connecting to seerver I guess, it shows up in the “preauthorized” tab, under inactive authentication sets, I can see the new request, and When I click accept, The device goes to the device group.,

But again, the whole idea of Preauth is to avoid clicking “accept” device right. Whats wrong now @alfrunes. Is this how PreAuth feature is? or Am I missing something ? Because again it requires human intervention

---

<div class="post-metadata">

**Author:** ![alfrunes](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/alfrunes/32/703_2.png) [@alfrunes](https://hub.mender.io/u/alfrunes)\
**Post date:** [July 27, 2020, 1:36pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/26 "2020-07-27T13:36:33Z")

</div>

Correct me if I’m wrong, but from what I can see, neither the public key nor the mac address matches between the preauth request and the actual (pending) device. From the above image and the comment before that I can see you used two different mac addresses, is that so? You need to set this value to the mac address of the device, same goes for the public key - you need to use the public key that the device is using (i.e. the public key-pair of the private key located at `/data/mender/mender-agent.pem` on the device).  
The “device” shown in the Preauthorized tab is not an actual device until a device is connected with a matching key pair and identity data - think of it as a “device reservation” created from the preauth request.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 1:46pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/27 "2020-07-27T13:46:09Z")

</div>

Hi @alfrunes,

Im using the same mac address, Its b8:27:eb:b4:b5:d2 for my RPi, and I have genereated the PUblic key using this section **Generate a client keypair** from [https://docs.mender.io/hosted/server-integration/preauthorizing-devices](https://docs.mender.io/hosted/server-integration/preauthorizing-devices) and then I have uploaded the Public key to the **Pre-authorized** tab in the server GUI.

But I have not done anything with the private.key which is generated from this [https://docs.mender.io/hosted/server-integration/preauthorizing-devices](https://docs.mender.io/hosted/server-integration/preauthorizing-devices). Where should I keep this Private.key in the device ???

1. Tell me what you meant by **you need to use the public key that the device is using (i.e. the public key-pair of the private key located at `/data/mender/mender-agent.pem` on the device).** , According to that link, pub.key is generated using that keygen-client knw?

---

<div class="post-metadata">

**Author:** ![alfrunes](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/alfrunes/32/703_2.png) [@alfrunes](https://hub.mender.io/u/alfrunes)\
**Post date:** [July 27, 2020, 1:49pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/28 "2020-07-27T13:49:52Z")

</div>

If you’re still having a hard time, you can fetch these parameters using ssh:

```auto
echo "Mac address:"
ssh root@${DEVICE_IP} -- /bin/sh /usr/share/mender/mender-identity-data
echo "Public key:"
ssh root@${DEVICE_IP} -- /bin/cat /var/lib/mender/mender-agent.pem | openssl rsa -pubout | awk '{printf "%s\\n", $0}'

```

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 1:51pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/29 "2020-07-27T13:51:06Z")

</div>

@alfrunes,  
So far I have used Mender-Client directly by installing and configuring thru those parameters, I have only folder /etc/mender, /usr/share/mender and /var/lib/mender-client., There is no /data/mender/mender-agent.pem

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 1:53pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/30 "2020-07-27T13:53:21Z")

</div>

> [@alfrunes](#):
>
> `/bin/cat /data/mender/mender-agent.pem`

I have the mender-agent.pem in /var/lib/mender/mender-agent.pem  
Where should I use this.

Its confirm, I’m using the mac address right only. It is from my RPi, and Public key generated frm that documentation(keygen-client) from the server.

---

<div class="post-metadata">

**Author:** ![alfrunes](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/alfrunes/32/703_2.png) [@alfrunes](https://hub.mender.io/u/alfrunes)\
**Post date:** [July 27, 2020, 1:59pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/31 "2020-07-27T13:59:27Z")

</div>

> [@nishad1092](#):
>
> I have the mender-agent.pem in /var/lib/mender/mender-agent.pem

Sorry, I was trying to recreate this on a device with a persistant data partition, but `/var/lib/mender/mender-agent.pem` is the right one. If you ran the keygen script, you need to replace the mender-agent.pem file with the generated private key.

---

<div class="post-metadata">

**Author:** ![nishad1092](https://avatars.discourse-cdn.com/v4/letter/n/5fc32e/32.png) [@nishad1092](https://hub.mender.io/u/nishad1092)\
**Post date:** [July 27, 2020, 2:10pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/32 "2020-07-27T14:10:31Z")

</div>

> [@alfrunes](#):
>
> `/bin/cat /data/mender/mender-agent.pem | openssl rsa -pubout | awk '{printf "%s\\n", $0}'`

So If I use this mender-agent.pem into the “Preauthorized” tab in the server and start mender-client, it gets connected, I guess It worked @alfrunes, I added this key to the server and just restart the mender-client, I didn’t even run the post-auth and thje device got preauthorized and go into running mode.

But, the whole idea of PreAuth I was thinking is to not access the Mender-Client(here RPi), and to reduce Human intervention, But here it involves alot of getting into device and taking the key etc.

Or Did I miss anything again.

---

<div class="post-metadata">

**Author:** ![alfrunes](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/alfrunes/32/703_2.png) [@alfrunes](https://hub.mender.io/u/alfrunes)\
**Post date:** [July 27, 2020, 2:29pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/33 "2020-07-27T14:29:55Z")

</div>

Usually you want to provision a new (known) private key once you install mender on the device. This way you know the public key ahead of time and will not require to reach out to the device to fetch it. As for the device identity, you can actually rewrite/modify the script located at `/usr/share/mender/mender-identity-data` on the device to use any kind of key/value pairs that floats your boat 🙂

---

<div class="post-metadata">

**Author:** ![triampmeili](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@triampmeili](https://hub.mender.io/u/triampmeili)\
**Post date:** [January 22, 2021, 5:48am UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/34 "2021-01-22T05:48:03Z")

</div>

![0f5b0b4b0bb08a2f034b87b16850f5de4218c4d9_2_690x165](https://canada1.discourse-cdn.com/flex036/uploads/mender/original/2X/e/e1f93500cc2224e006b8e1eea22d2595eea1ce41.png)

How to make the Public key value the same? Thanks!

---

<div class="post-metadata">

**Author:** ![alfrunes](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/alfrunes/32/703_2.png) [@alfrunes](https://hub.mender.io/u/alfrunes)\
**Post date:** [February 15, 2021, 10:03am UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/35 "2021-02-15T10:03:31Z")

</div>

@triampmeili you need to provision your private key to the device `/data/mender/mender-agent.pem`, otherwise the `mender-client` will generate a new key on bootstrap.

---

<div class="post-metadata">

**Author:** ![triampmeili](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@triampmeili](https://hub.mender.io/u/triampmeili)\
**Post date:** [March 8, 2021, 6:13am UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/36 "2021-03-08T06:13:43Z")

</div>

Can the preauthorizing devices be transformed into a real device and automatically accepted (via mender API or other methods)?

Thanks!

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [March 8, 2021, 2:40pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/37 "2021-03-08T14:40:06Z")

</div>

Hi @triampmeili that’s essentially what happens when the device connects for the first time. Can you elaborate on what you are trying to accomplish that is different from the default behavior?

Drew

---

<div class="post-metadata">

**Author:** ![triampmeili](https://avatars.discourse-cdn.com/v4/letter/t/ac8455/32.png) [@triampmeili](https://hub.mender.io/u/triampmeili)\
**Post date:** [March 9, 2021, 6:53am UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/38 "2021-03-09T06:53:01Z")

</div>

I know, we just want to change “the device connects for first time” into the above state(the preauthorizing devices be transformed into a real device and automatically accepted).can it be done?

---

<div class="post-metadata">

**Author:** ![drewmoseley](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/drewmoseley/32/47_2.png) [@drewmoseley](https://hub.mender.io/u/drewmoseley)\
**Post date:** [March 9, 2021, 2:14pm UTC](https://hub.mender.io/t/how-to-preauthorize-the-device/2235/39 "2021-03-09T14:14:32Z")

</div>

Assuming you don’t want to boot the device in manufacturing to do it, I guess you could call the [Authorize Device API](https://docs.mender.io/api/#device-api-device-authentication) from a scripting setup. That would require that you have the ID key-value pairs and the certificate for the device but presumably you already have them to be able to issue the pre-authorize API.

Drew

[Previous page](https://hub.mender.io/t/how-to-preauthorize-the-device/2235.md?page=1)
