# Curl -X GET 'https://localhost:9200'

**URL:** https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624
**Category:** Elasticsearch
**Created:** [June 21, 2023, 7:43pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624 "2023-06-21T19:43:46Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 21, 2023, 7:43pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/1 "2023-06-21T19:43:46Z")

</div>

```auto
curl -X GET 'https://localhost:9200'

curl: (60) Peer's certificate issuer has been marked as not trusted by the user.
More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
 of Certificate Authority (CA) public keys (CA certs). If the default
 bundle file isn't adequate, you can specify an alternate file
 using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
 the bundle, the certificate verification probably failed due to a
 problem with the certificate (it might be expired, or the name might
 not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
 the -k (or --insecure) option.

```

---

<div class="post-metadata">

### Author: ![DineshNaik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dineshnaik/32/89308_2.png) [@DineshNaik](https://discuss.elastic.co/u/DineshNaik)
#### Post date: [June 21, 2023, 7:48pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/2 "2023-06-21T19:48:40Z")

</div>

not sure whats your query here ?

but if you want to avoid this error then you can either :

1. Have the root CA installed in your truststore (java truststore)
2. use the command as `curl -X -k GET 'https://localhost:9200'`

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 21, 2023, 8:10pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/3 "2023-06-21T20:10:46Z")

</div>

Fiz a instalação do Elasticsearch 8 no centos 7,

 ![status-elasticsearch](https://us1.discourse-cdn.com/elastic/original/3X/a/5/a5c8a8933444c05044b55eb337cd8ce4fd4604c6.jpeg)

mas quando consulto seu funcionamento na porta 9200 dá esse erro.

Tem algum artigo que mostra como faz o procedimento que você mencionou?

---

<div class="post-metadata">

### Author: ![DineshNaik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dineshnaik/32/89308_2.png) [@DineshNaik](https://discuss.elastic.co/u/DineshNaik)
#### Post date: [June 21, 2023, 9:27pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/4 "2023-06-21T21:27:21Z")

</div>

Here it is [https://connect2id.com/blog/importing-ca-root-cert-into-jvm-trust-store](https://connect2id.com/blog/importing-ca-root-cert-into-jvm-trust-store)

You need to know the root certificate which was used to secure the cluster though.

If it's the default one from ES then please refer : [Set up basic security for the Elastic Stack plus secured HTTPS traffic | Elasticsearch Guide [8.8] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-basic-setup-https.html)

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 22, 2023, 5:22pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/7 "2023-06-22T17:22:17Z")

</div>

Obrigado pelos artigos! É possível importar ca\_bundle.crt?

Tentei resolver criando o certificado com os scripts do Elastic:

cd /usr/share/elasticsearch/  
./bin/elasticsearch-certutil ca  
./bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12  
./bin/elasticsearch-certutil http

mas na hora de criar usuário e senha tá dando erro

./bin/elasticsearch-setup-passwords auto -u "[http://127.0.0.1:9200](http://127.0.0.1:9200)"

```auto
ERROR: Failed to connect to elasticsearch at http://127.0.0.1:9200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running?

```

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 11:55am UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/8 "2023-06-26T11:55:06Z")

</div>

Alguém pode me ajudar?

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 26, 2023, 11:57am UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/9 "2023-06-26T11:57:22Z")

</div>

> [@codepan](#):
>
> `ERROR: Failed to connect to elasticsearch at http://127.0.0.1:9200/_security/_authenticate?pretty. Is the URL correct and elasticsearch running?`

De acordo com seu primeiro post o seu Elasticsearch tá rodando com `https`, você precisa fazer o curl pra `https`, não `http`.

Se der erro de certificado não reconhecido você precisa usar `-k` como parâmetro no curl.

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 12:02pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/10 "2023-06-26T12:02:31Z")

</div>

./bin/elasticsearch-setup-passwords auto -u "[https://127.0.0.1:9200](https://127.0.0.1:9200)"

```auto
Failed to authenticate user 'elastic' against https://127.0.0.1:9200/_security/_authenticate?pretty
Possible causes include:
 * The password for the 'elastic' user has already been changed on this cluster
 * Your elasticsearch node is running against a different keystore
   This tool used the keystore at /etc/elasticsearch/elasticsearch.keystore

You can use the `elasticsearch-reset-password` CLI tool to reset the password of the 'elastic' user

ERROR: Failed to verify bootstrap password

```

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 12:10pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/11 "2023-06-26T12:10:03Z")

</div>

./bin/elasticsearch-setup-passwords auto -u -k "[https://127.0.0.1:9200](https://127.0.0.1:9200)"

```auto
Exception in thread "main" java.net.MalformedURLException: no protocol: -k
        at java.base/java.net.URL.<init>(URL.java:764) at java.base/java.net.URL.<init>(URL.java:646)
        at java.base/java.net.URL.<init>(URL.java:582)
        at org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool$SetupCommand.setupOptions(SetupPasswordTool.java:307)
        at org.elasticsearch.xpack.security.authc.esnative.tool.SetupPasswordTool$AutoSetup.execute(SetupPasswordTool.java:146)
        at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
        at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:94)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
        at org.elasticsearch.cli.Command.main(Command.java:50)
        at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)

```

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 26, 2023, 12:21pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/12 "2023-06-26T12:21:52Z")

</div>

> [@codepan](#):
>
> ./bin/elasticsearch-setup-passwords auto -u -k "[https://127.0.0.1:9200](https://127.0.0.1:9200)"

O `-k` é pra usar no `curl`, não no `elasticsearch-setup-passwords`.

Você já gerou os passwords? Quando você instala pela primeira vez ele já gera as senhas pros usuários nativos, é isso que a primeira mensagem te disse.

> The password for the 'elastic' user has already been changed on this cluster

Se você precisa resetar a senha do usuário `elastic` você precisa usar o outro comando.

> You can use the `elasticsearch-reset-password` CLI tool to reset the password of the 'elastic' user

A documentação pra esse comando está [aqui](https://www.elastic.co/guide/en/elasticsearch/reference/current/reset-password.html).

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 12:35pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/13 "2023-06-26T12:35:14Z")

</div>

Não gerei a senha só fiz a instalação nas seguintes etapas:

sudo nano/etc/yum.repos.d/elasticsearch.repo

```auto
[elasticsearch-8.x]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

```

sudo rpm --import [https://artifacts.elastic.co/GPG-KEY-elasticsearch](https://artifacts.elastic.co/GPG-KEY-elasticsearch)  
sudo yum clean all  
sudo yum makecache  
sudo yum -y install elasticsearch  
sudo systemctl enable --now elasticsearch.service  
systemctl start elasticserarch

Mas deu erro ao iniciar o serviço, então fiz sua recomendação de criar:  
[Link artigo da solução](https://discuss.elastic.co/t/elasticsearch-code-exited-status-1-failure/336595/4)

```auto
cd /usr/share/elasticsearch
sudo mkdir tmp
sudo chown elasticsearch:elasticsearch tmp
sudo systemctl edit elasticsearch

```

Então o serviço funcionou, mas não consigo usar o comando Curl -X GET ‘[https://localhost:9200](https://localhost:9200)’

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 26, 2023, 12:39pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/14 "2023-06-26T12:39:03Z")

</div>

> [@codepan](#):
>
> Não gerei a senha só fiz a instalação nas seguintes etapas

Durante o processo de instalação ele cria automaticamente as senhas pros usuários nativos e mostra na tela, se você não copiou vai precisar regerar.

> [@codepan](#):
>
> Mas deu erro para iniciar o serviço

Qual o erro? No screenshot compartilhado o serviço tá rodando normal há mais de 3 horas, se desse erro para iniciar não mostraria isso.

Lembrando que no Elasticsearch 8 por padrão a segurança é habilitada é você precisa se autenticar pra fazer qualquer request.

`curl -k GET https://localhost:9200 -u elastic`, ai vai pedir a senha do usuário `elastic`.

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 12:48pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/15 "2023-06-26T12:48:38Z")

</div>

Desculpe-me! Reformulei minha resposta anterior com todos os passos executados desde a instalação até a correção do funcionamento do serviço.

Referente a curl -k GET [https://localhost:9200](https://localhost:9200) -u elastic, funcionou só que conforme você observou não anotei a senha gerada automaticamente.

```auto
curl -k GET https://localhost:9200 -u elastic
Enter host password for user 'elastic':

```

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 26, 2023, 12:50pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/16 "2023-06-26T12:50:35Z")

</div>

Você vai precisar resetar a senha então com o comando:

> You can use the `elasticsearch-reset-password` CLI tool to reset the password of the 'elastic' user

Só fazer como no [exemplo da documentação](https://www.elastic.co/guide/en/elasticsearch/reference/current/reset-password.html#_examples_8).

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 12:53pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/17 "2023-06-26T12:53:35Z")

</div>

usei o comando elasticsearch-reset-password no diretório /etc/elasticsearch

```auto
bash: elasticsearch-reset-password: command not found

```

Não estou sabendo usar o comando de forma correta.

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 26, 2023, 12:57pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/18 "2023-06-26T12:57:02Z")

</div>

> [@codepan](#):
>
> Usei o comando elasticsearch-reset-password no diretório /etc/elasticsearch

Esse comando fica no mesmo diretório que todos os outros comandos, o `/usr/share/elasticsearch` é o mesmo diretório de onde você executou o `elasticsearch-setup-passwords`.

---

<div class="post-metadata">

### Author: ![codepan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/codepan/32/122632_2.png) [@codepan](https://discuss.elastic.co/u/codepan)
#### Post date: [June 26, 2023, 1:07pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/19 "2023-06-26T13:07:25Z")

</div>

Segui os passos e o artigo de suas últimas respostas e funcionou normalmente!

**Segui até o repositório correto:**

```auto
cd /usr/share/elasticsearch

```

Redefinia a senha:

```auto
bin/elasticsearch-reset-password -u elastic

This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y

```

A senha foi gerada no terminal e usei ela no comando curl -k GET [https://localhost:9200](https://localhost:9200) -u elastic e tudo funcionou perfeitamente, muito obrigado! 🙂

Agora só preciso vincular o [elasticsearch no firewall](https://discuss.elastic.co/t/elastic-fireall-port-9200/336714/2) se puder me ajudar.

---

<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: [July 24, 2023, 1:08pm UTC](https://discuss.elastic.co/t/curl-x-get-https-localhost-9200/336624/20 "2023-07-24T13:08:24Z")

</div>

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