# How to setup a basic authentication for Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286>\
**Category:** Elasticsearch\
**Tags:** docker\
**Created:** [December 3, 2019, 5:05am UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286 "2019-12-03T05:05:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amandamlmia14](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@amandamlmia14](https://discuss.elastic.co/u/amandamlmia14)\
**Post date:** [December 3, 2019, 5:05am UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286/1 "2019-12-03T05:05:37Z")

</div>

I have a docker image of elasticsearch, version=7.0.1, I used the command to run the image

```
docker run -d -p 9200:9200 -p 9301:9301 --name elastic_search -e "discovery.type=single-node" -e "xpack.security.enabled=true" -e "ELASTICSEARCH_USERNAME=john" -e "ELASTICSEARCH_PASSWORD=deer" -v elastic_search_volume:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:7.0.1

```

Without porviding any credentials for my curl command, `curl localhost:9200`

I got the following output,

```
$ curl localhost:9200
% Total % Received % Xferd Average Speed Time Time Time Current
                             Dload Upload Total Spent Left Speed
100 508 100 508 0 0 26736 0 --:--:-- --:--:-- --:--:-- 28222{
"name" : "f1a397cdc93b",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "sBiiYUlsSM6e-RzJJcTvvg",
"version" : {
"number" : "7.0.1",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "e4efcb5",
"build_date" : "2019-04-29T12:56:03.145736Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.7.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}

```

Although, I have provided the credentials for the docker image while starting in the form of environmental variables, still I am able to access the database without providing the credentials.  
Even for the Kibana, without any configuration, still its able to access the database.

Can anyone help me on this?  
Thanks

---

<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:** [December 3, 2019, 8:04am UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286/2 "2019-12-03T08:04:58Z")

</div>

The problem is here: `7.0.1`

With this old version, you need a commercial license.  
Just use the latest version we released instead, 7.5.0 and you should be all set.  
At least use 7.1.x to have access to this free security feature.

---

<div class="post-metadata">

**Author:** ![amandamlmia14](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@amandamlmia14](https://discuss.elastic.co/u/amandamlmia14)\
**Post date:** [December 3, 2019, 8:11am UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286/3 "2019-12-03T08:11:27Z")

</div>

Thanks @dadoonet. Can you please share some information such that I can setup a basic username and password to the elasticsearch container.

If I update my Es version, is the docker command is correct for setting up the username which I was doing earlier?

Thanks

---

<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:** [December 3, 2019, 8:17am UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286/4 "2019-12-03T08:17:16Z")

</div>

I think you need to use `ELASTIC_PASSWORD` instead.  
I shared an example (docker-compose) here: [Create user in elasticsearch](https://discuss.elastic.co/t/create-user-in-elasticsearch/182401/2)

---

<div class="post-metadata">

**Author:** ![amandamlmia14](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@amandamlmia14](https://discuss.elastic.co/u/amandamlmia14)\
**Post date:** [December 3, 2019, 12:19pm UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286/5 "2019-12-03T12:19:06Z")

</div>

@dadoonet Thanks a lot, it worked. I wasn't able to find any documentation for the same, which cause such delay.

Thanks.

---

<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:** [December 31, 2019, 12:26pm UTC](https://discuss.elastic.co/t/how-to-setup-a-basic-authentication-for-elasticsearch/210286/6 "2019-12-31T12:26:47Z")

</div>

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