一、開啟密碼驗證
1、修改elasticsearch.yml文件,重啟ES
#允許head插件等訪問的相關設置
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
http.cors.allow-credentials: true
#是否啟用es的安全設置,啟用安全設置后es各節點、客戶端的傳輸都會加密,並需要賬號密碼
xpack.security.enabled: true
#此項不可更改,當啟用安全設置后,此項必須為true
xpack.security.transport.ssl.enabled: true
2、設置默認用戶密碼
./bin/elasticsearch-setup-passwords interactive
[elsearch@HN-82 bin]$ ./elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y
Enter password for [elastic]:
Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]
3、使用postman查詢ES中所有用戶信息。

注意:postman請求時,選擇【Authorization】->【Basic Auth】,添加ES的用戶名密碼后,就能訪問設置用戶名密碼的ES了。
二、添加新用戶以及修改密碼
Request edit
POST /_security/user/<username>
PUT /_security/user/<username>
{
"password" : "1234",
"roles" : [ "superuser" ],
"full_name" : "elastic-test",
"metadata" : {
"intelligence":7
}
}
Requestedit
POST /_security/user/_password
POST /_security/user/<username>/_password
POST /_security/user/elastic-test/_password
{
"password" : "43221"
}
三、忘記密碼如何重置
1、修改elasticsearch.yml文件,重啟ES
#是否啟用es的安全設置,啟用安全設置后es各節點、客戶端的傳輸都會加密,並需要賬號密碼
xpack.security.enabled: false
2、刪除 ES中.security-*的索引
curl -XDELETE localhost:9001/.security-6
{"acknowledged":true}
