# Unable to authenticate user for REST request

**URL:** <https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [May 4, 2021, 9:02pm UTC](https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116 "2021-05-04T21:02:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Egid](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@Egid](https://discuss.elastic.co/u/Egid)\
**Post date:** [May 4, 2021, 9:02pm UTC](https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116/1 "2021-05-04T21:02:00Z")

</div>

Hi

I am running the folowing comand:

```
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ELASTICSEARCH_USERNAME=egid" -e "ELASTICSEARCH_PASSWORD=black" -e "xpack.security.enabled=true" docker.elastic.co/elasticsearch/elasticsearch:7.12.0

```

Everything runs fine.

I do post request from postman: (I filled username and password like arguments in docker command)

 ![postman](https://us1.discourse-cdn.com/elastic/original/3X/7/4/7462a90ff14759621b063d72271d17701527a3cd.png)

When I try post request on elastic search with basic auth I got this::

I got:

```
{
  "error": {
      "root_cause": [
        {
          "type": "security_exception",
          "reason": "unable to authenticate user [egid] for REST request [/event5/_search]",
          "header": {
          "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
          }
        }
      ],
      "type": "security_exception",
     "reason": "unable to authenticate user [egid] for REST request [/event5/_search]",
     "header": {
        "WWW-Authenticate": "Basic realm=\"security\" charset=\"UTF-8\""
     }
  },
  "status": 401
}

```

Any ideas please ?🙂  
Thank you for any help

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 5, 2021, 6:48am UTC](https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116/2 "2021-05-05T06:48:03Z")

</div>

I never used myself the `ELASTICSEARCH_USERNAME` variable. Could you try with `elastic` as the username in postman instead?

---

<div class="post-metadata">

**Author:** ![Egid](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@Egid](https://discuss.elastic.co/u/Egid)\
**Post date:** [May 5, 2021, 7:13am UTC](https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116/3 "2021-05-05T07:13:39Z")

</div>

Thank you very much:

It worked 🙂 but I also had to change to docker command to:  
(use `ELASTIC_PASSWORD` instead of `ELASTICSEARCH_PASSWORD`)

```
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "ELASTIC_PASSWORD=black" -e "xpack.security.enabled=true" docker.elastic.co/elasticsearch/elasticsearch:7.12.0

```

also i did tried to play with `ELASTICSEARCH_USERNAME` and `ELASTIC_USERNAME`  
but no result

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 5, 2021, 7:30am UTC](https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116/4 "2021-05-05T07:30:47Z")

</div>

IIRC the `ELASTICSEARCH_PASSWORD` and `ELASTICSEARCH_USERNAME` are for the Kibana Docker image.

---

<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:** [June 2, 2021, 7:31am UTC](https://discuss.elastic.co/t/unable-to-authenticate-user-for-rest-request/272116/5 "2021-06-02T07:31:41Z")

</div>

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