# Create new cert and key from existing ca.crt : elasticsearch-certutil

**URL:** <https://discuss.elastic.co/t/create-new-cert-and-key-from-existing-ca-crt-elasticsearch-certutil/232529>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [May 14, 2020, 1:40am UTC](https://discuss.elastic.co/t/create-new-cert-and-key-from-existing-ca-crt-elasticsearch-certutil/232529 "2020-05-14T01:40:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dexterac](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dexterac](https://discuss.elastic.co/u/dexterac)\
**Post date:** [May 14, 2020, 1:40am UTC](https://discuss.elastic.co/t/create-new-cert-and-key-from-existing-ca-crt-elasticsearch-certutil/232529/1 "2020-05-14T01:40:42Z")

</div>

Initially when I created the ELK cluster I missed to include the Logstash and filebeat servers to generate the certificates: [https://www.elastic.co/blog/configuring-ssl-tls-and-https-to-secure-elasticsearch-kibana-beats-and-logstash#preparations](https://www.elastic.co/blog/configuring-ssl-tls-and-https-to-secure-elasticsearch-kibana-beats-and-logstash#preparations)

Created certificates and key files using this command :

```auto
bin/elasticsearch-certutil cert ca --pem --in ~/tmp/cert_blog/instance.yml --out ~/tmp/cert_blog/certs.zip

```

I saw this old discussion : [Elasticsearch didn't create ca.key. How can i create new key/crt for new instances?](https://discuss.elastic.co/t/elasticsearch-didnt-create-ca-key-how-can-i-create-new-key-crt-for-new-instances/215479)  
The blog article isn't updated on how to create new certificates using existing ca.crt.

I tried to run the above command with --keep-ca-key which create ca.crt and ca.key, however when i try to create new certificates for new servers added to the instance.yml it gives me this error message:

```auto
    /usr/share/elasticsearch/bin/elasticsearch-certutil cert ca --pem --in ~/tmp/cert_blog/instance.yml --out ~/tmp/cert_blog/certs-01.zip --ca-cert ~/tmp/cert_blog/certs/ca/ca.crt --ca-key ~/tmp/cert_blog/certs/ca/ca.key
This tool assists you in the generation of X.509 certificates and certificate
signing requests for use with SSL/TLS in the Elastic stack.

The 'cert' mode generates X.509 certificate and private keys.
    * By default, this generates a single certificate and key for use
       on a single instance.
    * The '-multiple' option will prompt you to enter details for multiple
       instances and will generate a certificate and key for each one
    * The '-in' option allows for the certificate generation to be automated by describing
       the details of each instance in a YAML file

    * An instance is any piece of the Elastic Stack that requires an SSL certificate.
      Depending on your configuration, Elasticsearch, Logstash, Kibana, and Beats
      may all require a certificate and private key.
    * The minimum required value for each instance is a name. This can simply be the
      hostname, which will be used as the Common Name of the certificate. A full
      distinguished name may also be used.
    * A filename value may be required for each instance. This is necessary when the
      name would result in an invalid file or directory name. The name provided here
      is used as the directory name (within the zip) and the prefix for the key and
      certificate files. The filename is required if you are prompted and the name
      is not displayed in the prompt.
    * IP addresses and DNS names are optional. Multiple values can be specified as a
      comma separated string. If no IP addresses or DNS names are provided, you may
      disable hostname verification in your SSL configuration.

    * All certificates generated by this tool will be signed by a certificate authority (CA).
    * The tool can automatically generate a new CA for you, or you can provide your own with the
         -ca or -ca-cert command line options.

By default the 'cert' mode produces a single PKCS#12 output file which holds:
    * The instance certificate
    * The private key for the instance certificate
    * The CA certificate

If you specify any of the following options:
    * -pem (PEM formatted output)
    * -keep-ca-key (retain generated CA key)
    * -multiple (generate multiple certificates)
    * -in (generate certificates from an input file)
then the output will be be a zip file containing individual certificate/key files

Exception in thread "main" java.lang.IllegalStateException: Error parsing Private Key from: /root/tmp/cert_blog/certs/ca/ca.key. File did not contain a supported key format
	at org.elasticsearch.xpack.core.ssl.PemUtils.readPrivateKey(PemUtils.java:104)
	at org.elasticsearch.xpack.security.cli.CertificateTool.readPrivateKey(CertificateTool.java:1025)
	at org.elasticsearch.xpack.security.cli.CertificateTool.access$200(CertificateTool.java:85)
	at org.elasticsearch.xpack.security.cli.CertificateTool$CertificateCommand.loadPemCA(CertificateTool.java:367)
	at org.elasticsearch.xpack.security.cli.CertificateTool$CertificateCommand.getCAInfo(CertificateTool.java:331)
	at org.elasticsearch.xpack.security.cli.CertificateTool$GenerateCertificateCommand.execute(CertificateTool.java:685)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
	at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:91)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:127)
	at org.elasticsearch.cli.Command.main(Command.java:90)
	at org.elasticsearch.xpack.security.cli.CertificateTool.main(CertificateTool.java:137)
-bash-4.2#

```

---

<div class="post-metadata">

**Author:** ![ikakavas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ikakavas/32/34430_2.png) [@ikakavas](https://discuss.elastic.co/u/ikakavas)\
**Post date:** [May 15, 2020, 6:24am UTC](https://discuss.elastic.co/t/create-new-cert-and-key-from-existing-ca-crt-elasticsearch-certutil/232529/2 "2020-05-15T06:24:14Z")

</div>

> [@dexterac](#):
>
> The blog article isn't updated on how to create new certificates using existing ca.crt.

There is no way to create certificates using _only_ an existing CA certificate, the blog would be updated to add a warning about this , not to add instructions about how to do something like this , as it _cannot_ be done.

> I tried to run the above command with --keep-ca-key which create ca.crt and ca.key

This created a _new_ CA key and certificate, it did not reuse the old one , just so that we are clear.

> [@dexterac](#):
>
> however when i try to create new certificates for new servers added to the instance.yml it gives me this error message:

a. You don't need to pass the `ca` parameter, you don;t need to generate a CA again, you have one.  
b. Your `--ca-key ~/tmp/cert_blog/certs/ca/ca.key` seems to be malformed somehow. What is the first line of that file?

---

<div class="post-metadata">

**Author:** ![dexterac](https://avatars.discourse-cdn.com/v4/letter/d/e47c2d/32.png) [@dexterac](https://discuss.elastic.co/u/dexterac)\
**Post date:** [May 27, 2020, 7:58pm UTC](https://discuss.elastic.co/t/create-new-cert-and-key-from-existing-ca-crt-elasticsearch-certutil/232529/3 "2020-05-27T19:58:18Z")

</div>

first line of ca.key : "-----BEGIN CERTIFICATE-----"

We ended up creating new certificates for all nodes and updating the config files to reflect to these while adding the new nodes. Sorry for late reply.

---

<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 24, 2020, 7:58pm UTC](https://discuss.elastic.co/t/create-new-cert-and-key-from-existing-ca-crt-elasticsearch-certutil/232529/4 "2020-06-24T19:58:19Z")

</div>

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