Certificado SSL gratuito con Let's Encrypt en Raspberry Pi

Certificado SSL de Let's Encrypt protegiendo conexión HTTPS
9 min. Lectura
0 Vistas
0 Valoración

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 está ejecutando correctamente y escuchando en el puerto 80, pero como estamos usando el servidor web ya existente no es necesario comprobar nada más.

Obtener el certificado SSL

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

Paso 1: Dirección de correo

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

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

Paso 2: Aceptar términos de servicio

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

Paso 3: Compartir email con EFF (opcional)

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

Paso 4: Nombre del dominio

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 continúa unos instantes más:

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

Paso 5: Ruta del webroot

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/

Finalización

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

Gestión de certificados

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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Cambiar email de la cuenta

Si decidimos que queremos cambiar el correo electrónico introducido en la configuración inicial, bastará 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

Continúa el proceso, y se detecta un certificado anterior y me pregunta qué deseo 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

Redirección HTTP a HTTPS

Al cabo de unos instantes, debemos escoger entre redireccionar el tráfico a HTTPS o no. Si no tenemos una razón para no redireccionar, responderemos que sí:

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 continúa:

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

Renovación automática con systemd

Los certificados de Let's Encrypt tienen una validez de 90 días, por lo que es importante configurar la renovación automática.

Crear servicio de renovación

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"

Crear timer de renovación

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

Activar renovación automática

Activamos y arrancamos el servicio:

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

Verificamos con:

sudo systemctl list-timers --all

¡Y listo! Tu Raspberry Pi ya tiene un certificado SSL válido y configurado para renovarse automáticamente cada 12 horas. Ahora todas las conexiones a tu servidor viajarán encriptadas mediante HTTPS.

¿Te ha sido útil?

Ayúdame a mejorar con tu puntuación y comentarios.

0.0 (0 votos)
Jaume Ferré

Jaume Ferré

Soy un entusiasta de las nuevas tecnologías, apasionado por explorar su potencial innovador. Colecciono CDs en formato físico y disfruto creando mezclas musicales. Además, la fotografía es otra de mis pasiones, capturando momentos y expresiones con cada disparo. ¡Gracias por leerme!

💬 Comentarios

Los comentarios están gestionados por GitHub Discussions. Necesitas una cuenta de GitHub para participar. ¡Es gratis y rápido!