'How to setup password for elasticsearch users?

I am trying to enable security for my ES cloud. I am following these instructions:

https://www.elastic.co/guide/en/elasticsearch/reference/7.5/configuring-security.html

and I am stuck at point 6. When I try to run bin/elasticsearch-setup-passwords interactive I got error:

Failed to determine the health of the cluster running at http://XXX:9200
Unexpected response code [503] from calling GET http://XXX:9200/_cluster/health?pretty
Cause: master_not_discovered_exception

It is recommended that you resolve the issues with your cluster before running elasticsearch-setup-passwords.
It is very likely that the password changes will fail when run against an unhealthy cluster.

Do you want to continue with the password setup process [y/N]

I try to check my ES instance state:

curl http://XXX:9200/_cluster/health?pretty

and get

{
  "error" : {
    "root_cause" : [
      {
        "type" : "security_exception",
        "reason" : "missing authentication credentials for REST request [/_cluster/health?pretty]",
        "header" : {
          "WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
        }
      }
    ],
    "type" : "security_exception",
    "reason" : "missing authentication credentials for REST request [/_cluster/health?pretty]",
    "header" : {
      "WWW-Authenticate" : "Basic realm=\"security\" charset=\"UTF-8\""
    }
  },
  "status" : 401
}

So, looks like I cant setup a password because I can`t authenticate :) ?



Solution 1:[1]

Here is the official doc for setting up security for Elasticsearch

step 1: cd /usr/share/elasticsearch/

step 2:

sudo bin/elasticsearch-setup-passwords auto

         

or

sudo bin/elasticsearch-setup-passwords interactive

auto - Uses randomly generated passwords interactive - Uses passwords entered by a user

The above commands can help you to setup password

Solution 2:[2]

The following worked for me in Windows.

Ensure elastic node is up and running. In a separate prompt, from elasticsearch/bin, run the below command

elasticsearch-setup-passwords auto -u "http://localhost:9200"

Elastic will ask you for proceeding with the setup of auto generated password. Once you proceed with yes, you will be provide with the password for elastic/kibana/beats etc.

Solution 3:[3]

for the windows run the elk in cmd
open other cmd and past the command where the elk in folder

bin/elasticsearch-setup-passwords auto

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Pritheka Kumar
Solution 3 Suraj Rao