Let's encrypt, certificado SSL para nuestra Raspberry

Instalar un certificado SSL local gratuito con Lets Encrypt

Si anteriormente aprendimos a utilizar un servicio de DNS dinámico para conectarnos a nuestra Raspberry, hoy vamos a añadir un certificado SSL para que nuestros datos viajen encriptados.


Todo el proceso lo haremos en la Raspberry que hace las funciones de servidor web. Nos conectamos mediante SSH, y empezamos instalando lo necesario:

sudo pacman -S certbot certbot-nginx

Antes de ejecutar el siguiente comando, deberíamos asegurarnos que el servidor se esta ejecutando correctamente y escuchando en el puerto 80, pero como estamos usando el servidor web ya existente no es necesario comprobar nada más.

Durante toda la operación deberemos ir introduciendo la información requerida. Empecemos:

sudo certbot certonly --webroot
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None

La primera información que se nos require, es una dirección de correo:

Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): r*******r@jaumeferre.net

A continuación se nos pide que leamos y aceptemos las condiciones de uso del servicio:

Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf.
You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

El siguiente paso es dar permiso a compartir la dirección de correo electrónico con un colaborador de Let’s encrypt:

Would you be willing to share your email address with the Electronic Frontier Foundation,
a founding partner of the Let's Encrypt project and the non-profit organization that
    develops Certbot? 
    We'd like to send you email about our work encrypting the web,
    EFF news, campaigns, and ways to support digital freedom.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (Y)es/(N)o: N

Continuamos introduciendo el nombre del dominio del certificado que estamos creando:

Please enter in your domain name(s) (comma and/or space separated)
(Enter 'c' to cancel): jaumeferre.m*******.com

El proceso continua unos instantes más:

Obtaining a new certificate
Performing the following challenges:
http-01 challenge for jaumeferre.m*******.com

Y para terminar, nos pide la ruta del dominio en el servidor:

Input the webroot for jaumeferre.m*******.com:
(Enter 'c' to cancel): /srv/http/jaumeferre.net/public_html/

Acaba el proceso:

Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/jaumeferre.m*******.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/jaumeferre.m*******.com/privkey.pem
Your cert will expire on 2020-02-21. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
 making regular backups of this folder is ideal.
    - If you like Certbot, please consider supporting our work by:

    Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
    Donating to EFF:                    https://eff.org/donate-le

Para ver los certificados que maneja certbot, utilizamos el siguiente comando:

sudo certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: jaumeferre.m*******.com
Domains: jaumeferre.m*******.com
Expiry Date: 2020-02-21 11:06:16+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/jaumeferre.m*******.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/jaumeferre.m*******.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Si decidimos que queremos cambiar el correo electronico introducido en la configuración inicial, bastara con ejecutar el comando siguiente:

certbot update_account --email nuevocorreo@email.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N

IMPORTANT NOTES:
 - Your e-mail address was updated to nuevocorreo@email.com.

Configurando Nginx

sudo certbot run --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx


Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: jaumeferre.m*******.com
2: jaumeferre.m*******.net
3: jaumeferre.m*******.org
4: jaumeferre.m*******.eu
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1

Continua el proceso, y se detecta un certificado anterior y me pregunta que desea hacer. Voy a renovar y reemplazar el existente:

Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/jaumeferre.m*******.com.conf)

What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Attempt to reinstall this existing certificate
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Al cabo de unos instantes, debemos escogeer entre redireccionar el trafico a HTTPS o no. Si no tenemos una razón para no redireccionar, responderemos que si.

Renewing an existing certificate
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/jaumeferre.net
2019/11/23 13:38:49 [notice] 6429#6429: signal process started

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

El proceso continua:

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/jaumeferre.net
2019/11/23 13:39:32 [notice] 6433#6433: signal process started

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Your existing certificate has been successfully renewed, and the new certificate
has been installed.

The new certificate covers the following domains:
https://jaumeferre.m*******.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=jaumeferre.m*******.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/jaumeferre.m*******.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/jaumeferre.m*******.com/privkey.pem
Your cert will expire on 2020-02-21. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
Donating to EFF:                    https://eff.org/donate-le

Renovando el certificado con systemd

Creamos el fichero certbot.service:

sudo nano /etc/systemd/system/certbot.service
[Unit]
Description=Let's Encrypt renewal

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --agree-tos --deploy-hook "systemctl reload nginx.service"

Creamos el fichero certbot.timer:

sudo nano /etc/systemd/system/certbot.timer
[Unit]
Description=Twice daily renewal of Let's Encrypt's certificates

[Timer]
OnCalendar=0/12:00:00
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target

Activamos y arrancamos el servicio:

sudo systemctl enable certbot.timer
sudo systemctl start certbot.timer

verificamos con:

sudo systemctl list-timers --all

Soy Jaume Ferré, aficionado a los nuevas tecnologias, aunque ya no lo son tanto.
¡Gracias por leerme!

Valora este artículo1 2 3 4 5 (0 votos)

(0 votos)

Categorias del blog

twitter

Últimos tweets