# Error initializing beat: could not initialize the keystore

**URL:** <https://discuss.elastic.co/t/error-initializing-beat-could-not-initialize-the-keystore/293847>\
**Category:** APM\
**Tags:** server\
**Created:** [January 10, 2022, 5:59am UTC](https://discuss.elastic.co/t/error-initializing-beat-could-not-initialize-the-keystore/293847 "2022-01-10T05:59:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramilbermejo](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@ramilbermejo](https://discuss.elastic.co/u/ramilbermejo)\
**Post date:** [January 10, 2022, 5:59am UTC](https://discuss.elastic.co/t/error-initializing-beat-could-not-initialize-the-keystore/293847/1 "2022-01-10T05:59:47Z")

</div>

Hi All,

Need some help on how I can make apm-server keystore work. For some reason it will fail to initialize the file if is not owned by root.

root@apm-server:~# apm-server keystore list  
error initializing beat: could not initialize the keystore: config file ("/var/lib/apm-server/apm-server.keystore") must be owned by the user identifier (uid=0) or root

root@apm-server:~# ll /var/lib/apm-server/  
-rw------- 1 apm-server apm-server 402 Jan 6 05:42 apm-server.keystore  
-rw------- 1 apm-server apm-server 0 Jan 7 05:28 apm-server.lock  
-rw------- 1 apm-server apm-server 48 Jun 30 2021 meta.json

If I change the ownership as root, the apm-server service won't start at all and it shows this error on system logs.

`Exiting: could not initialize the keystore: open /var/lib/apm-server/apm-server.keystore: permission denied`

Please advise on how to properly set its permissions or configuration to make it work.

---

<div class="post-metadata">

**Author:** ![marclop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marclop/32/119339_2.png) [@marclop](https://discuss.elastic.co/u/marclop)\
**Post date:** [January 10, 2022, 6:43am UTC](https://discuss.elastic.co/t/error-initializing-beat-could-not-initialize-the-keystore/293847/2 "2022-01-10T06:43:01Z")

</div>

As you experienced, I believe that the `apm-server keystore <add|list|remove>` commands will fail with an error if they aren't run with the user that owns the file.

The issue that you're seeing is caused because you're interacting with the `keystore` using root (as far as I can see in the console output that you provider), and the user that is running the `apm-server` binary is most likely not root.

To fix that, I'd advise that you add / list / delete keystore entries with the same user that runs `apm-server`.

---

<div class="post-metadata">

**Author:** ![ramilbermejo](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@ramilbermejo](https://discuss.elastic.co/u/ramilbermejo)\
**Post date:** [January 13, 2022, 4:10am UTC](https://discuss.elastic.co/t/error-initializing-beat-could-not-initialize-the-keystore/293847/3 "2022-01-13T04:10:49Z")

</div>

@marclop that works! thank you..

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 3, 2022, 12:10am UTC](https://discuss.elastic.co/t/error-initializing-beat-could-not-initialize-the-keystore/293847/4 "2022-02-03T00:10:59Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
