docs/content/obtain/_index.md
This guide explains various ways to get and renew a certificate.
<!--more-->These examples assume you have [lego installed]({{% ref "install" %}}). You can get a pre-built binary from the releases page.
{{< tabs groupid="usage-examples" >}} {{% tab title="Classic Way" %}}
Execute the following command:
lego run -d 'example.com' --http
{{% /tab %}} {{% tab title="With a Configuration File" %}}
Create a .lego.yml file with the following content:
certificates:
foo:
challenge: http-01
domains:
- example.com
And execute:
lego
{{% /tab %}} {{< /tabs >}}
{{< tabs groupid="usage-examples" >}} {{% tab title="Classic Way" %}}
Execute the following command:
CLOUDFLARE_EMAIL="[email protected]" \
CLOUDFLARE_API_KEY="yourprivatecloudflareapikey" \
lego run --dns cloudflare -d 'example.org' -d '*.example.org'
{{% /tab %}} {{% tab title="With a Configuration File" %}}
Create a .lego.yml file with the following content:
challenges:
cf:
dns:
provider: cloudflare
certificates:
foo:
domains:
- example.com
- '*.example.com'
And execute:
CLOUDFLARE_EMAIL="[email protected]" \
CLOUDFLARE_API_KEY="yourprivatecloudflareapikey" \
lego
{{% /tab %}} {{< /tabs >}}
You will find your certificates in the .lego folder of the current working directory:
$ ls -1 ./.lego/certificates
example.com.crt
example.com.issuer.crt
example.com.json
example.com.key
[maybe more files for different domains...]
where
example.com.crt is the server certificate (including the CA certificate),example.com.key is the private key needed for the server certificate,example.com.issuer.crt is the CA certificate, andexample.com.json contains some JSON encoded meta information.For each domain, you will have a set of these four files.
For wildcard certificates (*.example.com), the filenames will look like _.example.com.crt.
The .crt and .key files are PEM-encoded x509 certificates and private keys.
If you're looking for a cert.pem and privkey.pem, you can just use example.com.crt and example.com.key.
The first step in the process of obtaining certificates involves creating a signing request. This CSR bundles various information, including the domain name(s) and a public key. By default, lego will hide this step from you, but if you already have a CSR, you can easily reuse it:
{{< tabs groupid="usage-examples" >}} {{% tab title="Classic Way" %}}
Execute the following command:
lego run --http --csr="/path/to/csr.pem"
{{% /tab %}} {{% tab title="With a Configuration File" %}}
Create a .lego.yml file with the following content:
certificates:
foo:
csr: /path/to/csr.pem
challenge: http-01
domains:
- example.com
And execute:
lego
{{% /tab %}} {{< /tabs >}}
lego will infer the domains to be validated based on the contents of the CSR, so make sure the CSR's Common Name and SubjectAltNames are set correctly.
{{% children type="card" description="true" %}}