2
0
mirror of https://git.coolaj86.com/coolaj86/greenlock-cli.js synced 2025-02-23 11:38:05 +00:00
greenlock-cli.js/README.md

396 lines
12 KiB
Markdown
Raw Normal View History

2018-05-12 15:39:59 -06:00
![Greenlock Logo](https://git.coolaj86.com/coolaj86/greenlock.js/raw/branch/master/logo/greenlock-1063x250.png "Greenlock Logo")
2018-05-13 01:31:44 -06:00
# Greenlock™ Certificate Manager for Web Servers
2018-05-12 15:39:59 -06:00
A server-friendly commandline tool for Free SSL, Free Wildcard SSL, and Fully Automated HTTPS
<small>certificates issued by Let's Encrypt v2 via ACME</small>
Greenlock is also available
[for Browsers](https://git.coolaj86.com/coolaj86/greenlock.html),
[for node.js](https://git.coolaj86.com/coolaj86/greenlock-express.js),
and [for API integrations](https://git.coolaj86.com/coolaj86/greenlock.js)
2018-05-13 01:31:44 -06:00
Why use Greenlock? Two Reasons:
===============================
One
---
You want to be able to run a command like this:
```bash
sudo greenlock --domains example.com --config /etc/greenlock/greenlock.yml
```
And then get awesome results like this:
```
/etc/ssl/acme
├── accounts
│   └── acme-staging-v02.api.letsencrypt.org/directory
│   └── c07a31a70c691d64f6b4d31f51a6dd9c
│  ├── meta.json
│  ├── private_key.json
│  └── regr.json
└── live
   └── example.com <-- Free SSL like magic! Wow!
   ├── bundle.pem
   ├── cert.pem
   ├── chain.pem
    ├── fullchain.pem
    └── privkey.pem
```
That you use with your existing webserver - Apache, Nginx, HAProxy, node.js, etc
And install to renew so that you never worry about ssl again.
Two
---
You want to be able to run a command like this:
```bash
sudo greenlock --install systemd --config /etc/greenlock.yml --webroot '/srv/www/:hostname'
```
To immediately secure and publish any and all sites you have in a web root like this:
```
/srv/www/
├── coolsite.rocks
├── example.com
└── whatever.app
```
2018-05-12 15:39:59 -06:00
Features
========
2018-05-12 15:52:52 -06:00
- [x] Works with Windows, Mac, and Linux
- [x] Works with Apache, Nginx, node.js, HAProxy, etc
- [x] Great for VPS services - AWS, Digital Ocean, Vultr, etc
- [x] Great for Tiny Computers - Raspberry Pi, etc
2018-05-12 15:39:59 -06:00
- [x] Automatic HTTPS
- [x] Free SSL
- [x] Free Wildcard SSL
- [x] Multiple domain support (up to 100 altnames per SAN)
- [x] Virtual Hosting (vhost)
- [x] Automatical renewal (10 to 14 days before expiration)
2018-05-12 15:52:52 -06:00
- [x] Let's Encrypt v2 ACME API
2018-05-12 15:39:59 -06:00
- [x] Extensible via Plugins
- [x] HTTP Challenge Plugins - AWS S3, Azure, Consul, etcd
- [x] DNS Challenge Plugins - AWS Route53, CloudFlare, Digital Ocean
- [x] Account & Certificate Storage Plugins - AWS S3, Redis
2018-05-13 01:31:44 -06:00
- [x] Built-in WebServer
Install
=======
2018-05-12 15:39:59 -06:00
2018-05-13 01:31:44 -06:00
Mac
---
2018-05-12 15:39:59 -06:00
2018-05-13 01:31:44 -06:00
Open Terminal and run this install script:
2016-11-01 18:26:25 -06:00
2018-05-12 15:39:59 -06:00
```bash
2018-05-13 01:31:44 -06:00
curl -fsS https://get.greenlock.app/ | bash
2018-05-12 15:39:59 -06:00
```
2018-05-13 01:31:44 -06:00
Linux
-----
Open Terminal and run this install script:
2018-05-12 15:39:59 -06:00
```bash
2018-05-13 01:31:44 -06:00
curl -fsS https://get.greenlock.app/ | bash
2018-05-12 15:39:59 -06:00
```
2016-04-22 12:17:29 -06:00
2018-05-13 01:31:44 -06:00
Windows & Node.js
-----------------
1. Install [node.js](https://nodejs.org)
2. Open _Node.js_
2. Run the command `npm install -g greenlock-cli`
Important: How to Not Get Blocked
===================
PLEASE READ ALL THREE SENTENCES:
* These examples use the PRODUCTION ENVIRONMENT (where you can be blocked)
* If an example DOESN'T WORK on the first try, STOP!
* UNCOMMENT the `--staging` flag and see the TROUBLESHOOTING SECTION
Quick Examples
==============
The most basic options are exposed as commandline flags,
just so that we can do little domes like this.
The config file is explained after the troubleshooting section.
### The Greenlock HTTPS WebServer
Easy to run on your server, nothing else required:
2018-05-12 15:48:33 -06:00
```bash
2018-05-13 01:31:44 -06:00
sudo greenlock --webserver \
--agree-tos --email jon@example.com \
--domains example.com,www.example.com \
--webroot /srv/www/example.com \
--config-dir ~/acme/etc #--staging
2018-05-12 15:48:33 -06:00
```
2018-05-13 01:31:44 -06:00
### Add SSL to an Existing WebServer
2015-12-16 01:16:09 -08:00
2018-05-13 01:31:44 -06:00
For all the Apache, Nginx, and HAProxy fans out there:
2015-12-16 04:00:27 -08:00
2018-05-13 01:31:44 -06:00
(use your existing webroot)
2015-12-16 03:01:10 -08:00
2018-05-13 01:31:44 -06:00
```bash
sudo greenlock --agree-tos --email jon@example.com \
--domains example.com,www.example.com \
--webroot /srv/www/example.com \
--privkey-path /etc/ssl/example.com/privkey.pem \
--fullchain-path /etc/ssl/example.com/fullchain.pem \
--bundle-path /etc/ssl/example.com/bundle.pem \
--config-dir /etc/ssl/acme #--staging
```
2015-12-16 03:01:10 -08:00
2018-05-13 01:31:44 -06:00
### Get SSL Certificates Interactively
2015-12-16 03:01:10 -08:00
2018-05-13 01:31:44 -06:00
Run this manual process on your laptop and copy the certificates
to you server afterwards:
2015-12-16 03:01:10 -08:00
2018-05-12 15:39:59 -06:00
```bash
2018-05-13 01:31:44 -06:00
greenlock --agree-tos --email jon@example.com \
--domains example.com,www.example.com \
--privkey-path /etc/ssl/example.com/privkey.pem \
--fullchain-path /etc/ssl/example.com/fullchain.pem \
--bundle-path /etc/ssl/example.com/bundle.pem \
--manual \
--config-dir /etc/ssl/acme #--staging
2015-12-16 03:01:10 -08:00
```
2018-05-13 01:31:44 -06:00
### Standalone SSL Certificate Retrieval
Run this on a server standalone just to retrieve
certificates:
2015-12-16 01:16:09 -08:00
```bash
2018-05-13 01:31:44 -06:00
sudo greenlock --agree-tos --email jon@example.com \
--domains example.com,www.example.com \
--privkey-path /etc/ssl/example.com/privkey.pem \
--fullchain-path /etc/ssl/example.com/fullchain.pem \
--bundle-path /etc/ssl/example.com/bundle.pem \
--standalone \
--config-dir ~/etc/ssl/acme #--staging
2015-12-16 01:16:09 -08:00
```
2018-05-13 01:31:44 -06:00
Troubleshooting
===============
Watch the [Troubleshooting Screencast](https://youtu.be/e8vaR4CEZ5s?t=397)
**Note**: Replace `whatever.com` with your domain, use your real email, etc.
0. Use the `--staging` flag while troubleshooting
1. Do you have a valid A record for `whatever.com`?
2. When you `ping whatever.com` do you see that same address?
3. Can you confirm that's your server's address with `ifconfig` or `ipconfig`?
4. Do you have write access to all of the directories you've specified?
**Important**: Don't forget to delete the directory specified in `--config-dir`
when you get things figured out and remove `--staging`.
2018-05-12 15:39:59 -06:00
Usage
=====
2015-12-16 01:16:09 -08:00
2015-12-16 03:06:33 -08:00
These commands are shown using the **testing server**.
2015-12-19 14:30:56 -08:00
Want to use the **live server**?
2018-05-12 22:55:05 -06:00
1. change server to `--server https://acme-v02.api.letsencrypt.org/directory`
2015-12-16 03:06:33 -08:00
**Note**: This has really only been tested with single domains so if
multiple domains doesn't work for you, file a bug.
### Standalone (primarily for testing)
2015-12-16 01:16:09 -08:00
You can run standalone mode to get a cert **on the server**. You either use an
http-01 challenge (the default) on port 80, or a tls-sni-01 challenge on port
443 (or 5001). Like so:
2015-12-19 20:46:24 +00:00
2015-12-16 01:16:09 -08:00
```bash
2017-01-25 14:42:01 -07:00
greenlock certonly \
2015-12-16 01:16:09 -08:00
--agree-tos --email john.doe@example.com \
--standalone \
2015-12-16 03:06:33 -08:00
--domains example.com,www.example.com \
2018-05-12 22:55:05 -06:00
--server https://acme-staging-v02.api.letsencrypt.org/directory \
--acme-version draft-11
--config-dir ~/acme/etc
2015-12-19 20:46:24 +00:00
```
or
```bash
2017-01-25 14:42:01 -07:00
greenlock certonly \
--agree-tos --email john.doe@example.com \
--standalone --tls-sni-01-port 443 \
--domains example.com,www.example.com \
2018-05-12 22:55:05 -06:00
--server https://acme-staging-v02.api.letsencrypt.org/directory \
--acme-version draft-11
--config-dir ~/acme/etc
```
2015-12-19 20:46:24 +00:00
Then you can see your certs at `~/letsencrypt/etc/live`.
2015-12-16 04:58:05 -08:00
2015-12-19 20:46:24 +00:00
```
2015-12-16 05:02:09 -08:00
ls ~/letsencrypt/etc/live
2015-12-16 01:16:09 -08:00
```
2015-12-19 20:46:24 +00:00
This option is great for testing, but since it requires the use of
the same ports that your webserver needs, it isn't a good choice
for production.
2018-05-13 01:31:44 -06:00
### WebRoot
2015-12-19 20:46:24 +00:00
You can specify the path to where you keep your `index.html` with `webroot`, as
long as your server is serving plain HTTP on port 80.
2015-12-19 20:46:24 +00:00
For example, if I want to get a domain for `example.com` and my `index.html` is
at `/srv/www/example.com`, then I would use this command:
2015-12-16 01:16:09 -08:00
```bash
2017-01-25 14:42:01 -07:00
sudo greenlock certonly \
2015-12-16 01:16:09 -08:00
--agree-tos --email john.doe@example.com \
2015-12-19 20:46:24 +00:00
--webroot --webroot-path /srv/www/example.com \
2015-12-16 05:02:09 -08:00
--config-dir /etc/letsencrypt \
2015-12-16 03:06:33 -08:00
--domains example.com,www.example.com \
2018-05-12 22:55:05 -06:00
--server https://acme-staging-v02.api.letsencrypt.org/directory
--acme-version draft-11
2015-12-19 20:46:24 +00:00
```
Note that we use `sudo` because in this example we are using `/etc/letsencrypt`
as the cert directory rather than `~/letsencrypt/etc`, which we used in the previous example.
2015-12-16 04:58:05 -08:00
2015-12-19 20:46:24 +00:00
Then see your brand new shiny certs:
```
2015-12-16 05:02:09 -08:00
ls /etc/letsencrypt/live/
2015-12-16 01:16:09 -08:00
```
2015-12-16 11:01:10 +00:00
2015-12-19 20:46:24 +00:00
You can use a cron job to run the script above every 80 days (the certificates expire after 90 days)
so that you always have fresh certificates.
### Interactive (for debugging)
The token (for all challenge types) and keyAuthorization (only for https-01)
will be printed to the screen and you will be given time to copy it wherever
(file, dns record, database, etc) and the process will complete once you hit `enter`.
```bash
2017-01-25 14:42:01 -07:00
sudo greenlock certonly \
--agree-tos --email john.doe@example.com \
--manual
2018-05-12 22:55:05 -06:00
--config-dir /etc/acme \
--domains example.com,www.example.com \
2018-05-12 22:55:05 -06:00
--server https://acme-staging-v02.api.letsencrypt.org/directory
--acme-version draft-11
```
2015-12-16 05:32:00 -08:00
## Test with a free domain
```bash
# Install Daplie DNS
npm install -g ddns-cli
# see terms of use
ddns --help
# agree to terms and get domain
ddns --random --email user@example.com --agree
2015-12-16 05:33:17 -08:00
# the default is to use the ip address from which
# you can the command, but you can also assign the
# ip manually
ddns --random --email user@example.com --agree -a '127.0.0.1'
2015-12-16 05:32:00 -08:00
```
Example domain:
```
rubber-duck-42.daplie.me
```
2015-12-16 03:16:25 -08:00
## Run without Root
If you'd like to allow node.js to use privileged ports `80` and `443`
(and everything under 1024 really) without being run as `root` or `sudo`,
you can use `setcap` to do so. (it may need to be run any time you reinstall node as well)
```bash
sudo setcap cap_net_bind_service=+ep /usr/local/bin/node
```
2017-01-25 14:42:01 -07:00
By default `node-greenlock` assumes your home directory `~/letsencrypt/`, but if
2015-12-16 05:02:09 -08:00
you really want to use `/etc/letsencrypt`, `/var/lib/letsencrypt/`, and `/var/log/letsencrypt`
you could change the permissions on them. **Probably a BAD IDEA**. Probabry a security risk.
```
# PROBABLY A BAD IDEA
2016-08-09 22:39:39 -04:00
sudo chown -R $(whoami) /etc/letsencrypt /var/lib/letsencrypt /var/log/letsencrypt
2015-12-16 05:02:09 -08:00
```
## Command Line Options
2015-12-16 11:01:10 +00:00
```
Usage:
2017-01-25 14:42:01 -07:00
greenlock [OPTIONS] [ARGS]
2015-12-16 11:01:10 +00:00
Options:
--server [STRING] ACME Directory Resource URI. (Default is https://acme-v01.api.letsencrypt.org/directory))
2015-12-16 11:01:10 +00:00
--email EMAIL Email used for registration and recovery contact. (default: null)
2015-12-16 11:01:10 +00:00
--agree-tos BOOLEAN Agree to the Let's Encrypt Subscriber Agreement
--domains URL Domain names to apply. For multiple domains you can enter a comma
separated list of domains as a parameter. (default: [])
2015-12-16 11:01:10 +00:00
--renew-within [NUMBER] Renew certificates this many days before expiry. (default: 7)
2016-08-09 22:39:39 -04:00
2015-12-16 11:01:10 +00:00
--cert-path STRING Path to where new cert.pem is saved
(Default is :conf/live/:hostname/cert.pem)
--fullchain-path [STRING] Path to where new fullchain.pem (cert + chain) is saved
(Default is :conf/live/:hostname/fullchain.pem)
--chain-path [STRING] Path to where new chain.pem is saved
(Default is :conf/live/:hostname/chain.pem)
--domain-key-path STRING Path to privkey.pem to use for domain (default: generate new)
2015-12-16 03:17:06 -08:00
--config-dir STRING Configuration directory. (Default is ~/letsencrypt/etc/)
2015-12-16 11:01:10 +00:00
--http-01-port [NUMBER] Use HTTP-01 challenge type with this port, used for SimpleHttp challenge. (Default is 80)
(must be 80 with most production servers)
--dns-01 Use DNS-01 challenge type.
--standalone [BOOLEAN] Obtain certs using a "standalone" webserver. (Default is true)
--manual [BOOLEAN] Print the token and key to the screen and wait for you to hit enter,
giving you time to copy it somewhere before continuing. (Default is false)
--webroot BOOLEAN Obtain certs by placing files in a webroot directory.
--webroot-path STRING public_html / webroot path.
2015-12-16 11:01:10 +00:00
--debug BOOLEAN show traces and logs
2015-12-16 11:01:10 +00:00
-h, --help Display help and usage details
```
2015-12-16 05:03:03 -08:00
Note: some of the options may not be fully implemented. If you encounter a problem, please report a bug on the issues page.