One place for hosting & domains

      How To Acquire a Let’s Encrypt Certificate Using DNS Validation with certbot-dns-digitalocean on Ubuntu 20.04


      The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      The majority of Let’s Encrypt certificates are issued using HTTP validation, which allows for the installation of certificates on a single server. However, HTTP validation is not always suitable for issuing certificates for use on load-balanced websites, nor can you use this validation to issue wildcard certificates.

      DNS validation allows for certificate issuance requests to be verified using DNS records, rather than by serving content over HTTP. This means that certificates can be issued simultaneously for a cluster of web servers running behind a load balancer, or for a system that isn’t directly accessible over the internet.

      In this tutorial, you will use the certbot-dns-digitalocean hook for Certbot to issue a Let’s Encrypt certificate using DNS validation via the DigitalOcean API.

      You can use the certbot-dns-digitalocean tool to integrate Certbot with DigitalOcean’s DNS management API, allowing the certificate validation records to be automatically configured on-the-fly when you request a certificate.

      Another key benefit of certbot-dns-digitalocean is that you can use it to issue certificates for individual servers that may be running behind a load balancer, or are otherwise not directly accessible over HTTP. In these cases, you can’t use traditional HTTP certificate validation, unless you set the validation files on each and every server, which can be inconvenient. The certbot-dns-digitalocean tool is also useful if you want to issue a certificate for a server that isn’t accessible over the internet, for example an internal system or staging environment.

      certbot-dns-digitalocean also fully supports wildcard certificates, which can only be issued using DNS validation.

      Prerequisites

      To complete this tutorial, you will need:

      • An Ubuntu 20.04 server set up by following the Initial Server Setup with Ubuntu 20.04, including a sudo non-root user.

      • A domain name managed via your DigitalOcean account—that is, for managing DNS records. In this particular example, we will use your_domain and subdomain.your_domain, as well as *.your_domain for a wildcard certificate, however you can adjust this for other domains or subdomains if required.

      • A DigitalOcean API key (Personal Access Token) with read and write permissions. To create one, visit How to Create a Personal Access Token.

      Once you have these ready, log in to your server as your non-root user to begin.

      Step 1 — Installing Certbot

      In this step, you will install Certbot, which is a program to issue and manage Let’s Encrypt certificates.

      Certbot is available within the official Ubuntu Apt repositories, so you can install it using the default system package manager:

      • sudo apt update
      • sudo apt install certbot

      Once the installation has completed, you can check with the following command:

      This will output something similar to the following:

      Output

      certbot 0.40.0

      In this step you installed Certbot. Next, you will download and install the acme-dns-certbot hook.

      Step 2 — Installing and Configuring certbot-dns-digitalocean

      Now that you’ve installed the base Certbot program, you can download and install certbot-dns-digitalocean, which will allow Certbot to operate in DNS validation mode using the DigitalOcean DNS management API.

      Like Certbot itself, which you installed in Step 1, the certbot-dns-digitalocean utility is available within Ubuntu’s default repositories. However, the Certbot repository contains a more reliably updated version, so it is always recommended to use this where possible.

      Continue by installing the package for certbot-dns-digitalocean:

      • sudo apt install python3-certbot-dns-digitalocean

      Once the installation has completed, you need to set up a configuration file containing the DigitalOcean API key/Personal Access Token that you generated as part of the prerequisites.

      Begin by creating the creds.ini file in a private location:

      • touch ~/certbot-creds.ini

      Next, restrict the permissions on the file in order to make sure no other user on your server can read it:

      • chmod go-rwx ~/certbot-creds.ini

      Finally, open the file using your text editor and add your DigitalOcean access token:

      The content of the file will be as follows:

      ~/certbot-creds.ini

      dns_digitalocean_token = your_digitalocean_access_token
      

      Once done, save and close the file.

      Warning: Your DigitalOcean access token grants access to your DigitalOcean account, so you must protect it as you would a password. Do not share it with anyone or check it into a public code repository.

      In this step, you downloaded and installed the certbot-dns-digitalocean utility and created a configuration file containing your API credentials.

      Step 3 — Issuing a Certificate

      In this step, you’ll issue a certificate using Certbot and the DigitalOcean API.

      To issue your first certificate, run Certbot using the following arguments, making sure to specify the correct path to your credentials file as well as your domains:

      • sudo certbot certonly --dns-digitalocean --dns-digitalocean-credentials ~/certbot-creds.ini -d your_domain -d subdomain.your_domain

      Note: If you see an unsafe permissions on credentials configuration file warning, this indicates that the file permissions have not been correctly restricted, thus allowing other users on your server to access your token. Please double-check with the chmod command in Step 2.

      Certbot will take a few seconds to request the certificate; you will then receive a message confirming that it has issued your certificate:

      Output

      ... Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/your_domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/your_domain/privkey.pem ...

      In the event that the certificate issuance fails, this may be because there wasn’t sufficient time for the DNS changes to propagate. You can optionally increase the DNS propagation delay to give more time for the verification DNS records to propagate and be picked up by Let’s Encrypt. The delay is 10 seconds by default, but you can increase this using the --dns-digitalocean-propagation-seconds argument:

      • sudo certbot certonly --dns-digitalocean --dns-digitalocean-credentials ~/certbot-creds.ini --dns-digitalocean-propagation-seconds 30 -d your_domain -d subdomain.your_domain

      Finally, you can also use certbot-dns-digitalocean to issue wildcard certificates for your domain:

      • sudo certbot certonly --dns-digitalocean --dns-digitalocean-credentials ~/certbot-creds.ini -d *.your_domain

      Note: In some cases, requesting multiple certificates for the same hostnames in a short time period can cause issuance to begin failing. This is due to rate limits and the DNS time-to-live (TTL) value, which can sometimes cause delays in new DNS changes being propagated.

      To mitigate this, you may wish to wait out the duration of the TTL, or consider adjusting the --dns-digitalocean-propagation-seconds option that was detailed earlier in this step.

      In this step, you used Certbot with certbot-dns-digitalocean for the first time and issued your initial certificates.

      Step 4 — Renewing Certificates

      In this final step, you will renew certificates using Certbot with certbot-dns-digitalocean.

      Once your certificates are nearing expiry, Certbot is able to automatically renew them for you:

      The renewal process can run start-to-finish without user interaction. It will also remember the configuration options that you specified during the initial setup.

      By default, Certbot will run this as an automatic scheduled system task, meaning that no further maintenance is needed for your certificates. You can check that the scheduled task has been correctly installed by printing out the status of the associated system service, which is certbot.timer:

      • sudo systemctl status certbot.timer

      This will output something similar to the following, which shows the loaded task scheduled to run twice per day:

      Output

      ● certbot.timer - Run certbot twice daily Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled) Active: active (waiting) since Sun 2020-11-22 18:18:40 UTC; 2 weeks 6 days ago Trigger: Sun 2020-12-13 7:17:57 UTC; 11h left Nov 22 18:18:40 droplet1 systemd[1]: Started Run certbot twice daily.

      However, to test that this is working without having to wait until nearer the expiry date of your certificate(s), you can trigger a ‘dry run’. This will simulate the renewal process without making any actual changes to your configuration.

      You can trigger a dry run using the standard renew command, but with the --dry-run argument:

      • sudo certbot renew --dry-run

      This will output something similar to the following, which will provide assurance that the renewal process is functioning correctly:

      Output

      ... Cert not due for renewal, but simulating renewal for dry run Plugins selected: Authenticator dns-digitalocean, Installer None Renewing an existing certificate Performing the following challenges: dns-01 challenge for your_domain dns-01 challenge for subdomain.your_domain Waiting 10 seconds for DNS changes to propagate Waiting for verification... Cleaning up challenges ...

      In this final step, you tested the automatic renewal process within Certbot.

      Conclusion

      In this tutorial, you set up Certbot with certbot-dns-digitalocean to issue certificates using DNS validation with the DigitalOcean DNS management API.

      If you’re interested in learning more about certbot-dns-digitalocean, you may wish to review the official documentation for the utility:

      Alternatively, if you aren’t using DigitalOcean to manage your DNS records, you may wish to check out How to Acquire a Let’s Encrypt Certificate using DNS Validation with acme-dns-certbot on Ubuntu 18.04, which is a provider-agnostic alternative to certbot-dns-digitalocean.

      Finally, if you would like some further technical reading, you could dig into the details of ACME DNS validation by reviewing the relevant section of the official RFC document, which outlines how the process works:



      Source link

      How To Secure Nginx with Let’s Encrypt on CentOS 8


      Not using CentOS 8?


      Choose a different version or distribution.

      The author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program.

      Introduction

      Let’s Encrypt is a certificate authority (CA) that provides free certificates for Transport Layer Security (TLS) encryption. It simplifies the process of creation, validation, signing, installation, and renewal of certificates by providing a software client—Certbot.

      In this tutorial you’ll set up a TLS/SSL certificate from Let’s Encrypt on a CentOS 8 server running Nginx as a web server. Additionally, you will automate the certificate renewal process using a cron job.

      Prerequisites

      In order to complete this guide, you will need:

      • One CentOS 8 server set up by following the CentOS 8 Initial Server Setup guide, including a non-root user with sudo privileges and a firewall.
      • Nginx installed on the CentOS 8 server with a configured server block. You can learn how to set this up by following our tutorial How To Install Nginx on CentOS 8.
      • A fully registered domain name. This tutorial will use your_domain as an example throughout. You can purchase a domain name on Namecheap, get one for free on Freenom, or use the domain registrar of your choice.
      • Both of the following DNS records set up for your server. You can follow this introduction to DigitalOcean DNS for details on how to add them.
        • An A record with your_domain pointing to your server’s public IP address.
        • An A record with www.your_domain pointing to your server’s public IP address.

      Step 1 — Installing the Certbot Let’s Encrypt Client

      First, you need to install the certbot software package. Log in to your CentOS 8 machine as your non-root user:

      The certbot package is not available through the package manager by default. You will need to enable the EPEL repository to install Certbot.

      To add the CentOS 8 EPEL repository, run the following command:

      • sudo dnf install epel-release

      When asked to confirm the installation, type and enter y.

      Now that you have access to the extra repository, install all of the required packages:

      • sudo dnf install certbot python3-certbot-nginx

      This will install Certbot itself and the Nginx plugin for Certbot, which is needed to run the program.

      The installation process will ask you about importing a GPG key. Confirm it so the installation can complete.

      You have now installed the Let’s Encrypt client, but before obtaining certificates, you need to make sure that all required ports are open. To do this, you will update your firewall settings in the next step.

      Step 2 — Updating the Firewall Rules

      Since your prerequisite setup enables firewalld, you will need to adjust the firewall settings in order to allow external connections on your Nginx web server.

      To check which services are already enabled, run the command:

      • sudo firewall-cmd --permanent --list-all

      You’ll receive output like this:

      Output

      public target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client http ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:

      If you do not see http in the services list, enable it by running:

      • sudo firewall-cmd --permanent --add-service=http

      To allow https traffic, run the following command:

      • sudo firewall-cmd --permanent --add-service=https

      To apply the changes, you’ll need to reload the firewall service:

      • sudo firewall-cmd --reload

      Now that you’ve opened up your server to https traffic, you’re ready to run Certbot and fetch your certificates.

      Step 3 — Obtaining a Certificate

      Now you can request an SSL certificate for your domain.

      When generating the SSL Certificate for Nginx using the certbot Let’s Encrypt client, the client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.

      If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be the base domain used by Let’s Encrypt to create the certificate, and for that reason you will pass the top-level domain name as first in the list, followed by any additional subdomains or aliases:

      • sudo certbot --nginx -d your_domain -d www.your_domain

      This runs certbot with the --nginx plugin, and the base domain will be your_domain. To execute the interactive installation and obtain a certificate that covers only a single domain, run the certbot command with:

      • sudo certbot --nginx -d your_domain

      The certbot utility can also prompt you for domain information during the certificate request procedure. To use this functionality, call certbot without any domains:

      You will receive a step-by-step guide to customize your certificate options. Certbot will ask you to provide an email address for lost key recovery and notices and to agree to the terms of service. If you did not specify your domains on the command line, Certbot will look for a server_name directive and will give you a list of the domain names found. If your server block files do not specify the domain they serve explicitly using the server_name directive, Certbot will ask you to provide domain names manually.

      For better security, Certbot will automatically configure redirecting all traffic on port 80 to 443.

      When the installation successfully finishes, you will receive a message similar to this:

      Output

      IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/your_domain/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/your_domain/privkey.pem Your cert will expire on 2021-02-26. 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

      The generated certificate files will be available within a subdirectory named after your base domain in the /etc/letsencrypt/live directory.

      Now that you have finished using Certbot, you can check your SSL certificate status. Verify the status of your SSL certificate by opening the following link in your preferred web browser (don’t forget to replace your_domain with your base domain):

      https://www.ssllabs.com/ssltest/analyze.html?d=your_domain
      

      This site contains an SSL test from SSL Labs, which will start automatically. At the time of this writing, default settings will give an A rating.

      You can now access your website using the https prefix. However, you must renew certificates periodically to keep this setup working. In the next step, you will automate this renewal process.

      Step 4 — Setting Up Auto-Renewal

      Let’s Encrypt certificates are valid for 90 days, but it’s recommended that you renew the certificates every 60 days to allow for a margin of error. The Certbot Let’s Encrypt client has a renew command that automatically checks the currently installed certificates and tries to renew them if they are less than 30 days away from the expiration date.

      You can test automatic renewal for your certificates by running this command:

      • sudo certbot renew --dry-run

      The output will be similar to this:

      Output

      Saving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/your_domain.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cert not due for renewal, but simulating renewal for dry run Plugins selected: Authenticator nginx, Installer nginx Renewing an existing certificate Performing the following challenges: http-01 challenge for monitoring.pp.ua Waiting for verification... Cleaning up challenges - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - new certificate deployed with reload of nginx server; fullchain is /etc/letsencrypt/live/your_domain/fullchain.pem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ** DRY RUN: simulating 'certbot renew' close to cert expiry ** (The test certificates below have not been saved.) Congratulations, all renewals succeeded. The following certs have been renewed: /etc/letsencrypt/live/your_domain/fullchain.pem (success) ...

      Notice that if you created a bundled certificate with multiple domains, only the base domain name will show in the output, but the renewal will work for all domains included in this certificate.

      A practical way to ensure your certificates will not get outdated is to create a cron job that will periodically execute the automatic renewal command for you. Since the renewal first checks for the expiration date and only executes the renewal if the certificate is less than 30 days away from expiration, it is safe to create a cron job that runs every week, or even every day.

      Edit the crontab to create a new job that will run the renewal twice per day. To edit the crontab for the root user, run:

      Your text editor will open the default crontab, which is an empty text file at this point. Enter insert mode by pressing i and add in the following line:

      crontab

      0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew --quiet
      

      When you’re finished, press ESC to leave insert mode, then :wq and ENTER to save and exit the file. To learn more about the text editor Vi and its successor Vim, check out our Installing and Using the Vim Text Editor on a Cloud Server tutorial.

      This will create a new cron job that will execute at noon and midnight every day. python -c 'import random; import time; time.sleep(random.random() * 3600)' will select a random minute within the hour for your renewal tasks.

      The renew command for Certbot will check all certificates installed on the system and update any that are set to expire in less than thirty days. --quiet tells Certbot not to output information or wait for user input.

      More detailed information about renewal can be found in the Certbot documentation.

      Conclusion

      In this guide, you installed the Let’s Encrypt client Certbot, downloaded SSL certificates for your domain, and set up automatic certificate renewal. If you have any questions about using Certbot, you can check the official Certbot documentation.

      You can also check the official Let’s Encrypt blog for important updates from time to time.



      Source link

      Cara Mengamankan Apache dengan Let’s Encrypt pada Ubuntu 20.04


      Pengantar

      Let’s Encrypt adalah Otoritas Sertifikat (CA) yang memfasilitasi perolehan dan penginstalan sertifikat TLS/SSL gratis, yang dengan demikian mengaktifkan HTTPS terenkripsi pada server web. Ini menyederhanakan proses dengan menyediakan klien perangkat lunak, Certbot, yang berusaha mengotomatiskan sebagian besar (jika bukan semua) langkah yang diperlukan. Saat ini, seluruh proses memperoleh dan menginstal sertifikat secara sepenuhnya berjalan otomatis baik pada Apache dan Nginx.

      Dalam panduan ini, kita akan menggunakan Certbot untuk memperoleh sertifikat SSL gratis untuk Apache pada Ubuntu 20.04, dan memastikan agar sertifikat ini disiapkan untuk diperbarui secara otomatis.

      Tutorial ini menggunakan berkas hos virtual yang terpisah alih-alih berkas konfigurasi asali Apache untuk menyiapkan situs web yang akan diamankan dengan Let’s Encrypt. Kami menyarankan untuk menciptakan berkas hos virtual Apache yang baru untuk setiap domain yang dihos di server, karena ini membantu menghindari kesalahan umum dan mempertahankan berkas konfigurasi asali sebagai penyiapan fallback.

      Prasyarat

      Untuk mengikuti tutorial ini, Anda akan membutuhkan:

      • Satu server Ubuntu 20.04 yang disiapkan dengan mengikuti tutorial penyiapan server awal untuk Ubuntu 20.04 ini, termasuk satu pengguna non-root sudo dan satu firewall.

      • Nama domain yang terdaftar penuh. Tutorial ini akan menggunakan your_domain sebagai contoh di seluruh tulisan ini. Anda dapat membeli nama domain dari Namecheap, mendapat nama domain gratis di Freenom, atau menggunakan registrar domain pilihan Anda.

      • Kedua catatan DNS berikut disiapkan untuk server Anda. Anda dapat mengikuti pengantar DigitalOcean DNS ini untuk detail tentang cara menambahkannya.

        • Catatan A dengan your_domain yang mengarahkan ke alamat IP publik server Anda.
        • Catatan A dengan www.your_domain yang mengarahkan ke alamat IP publik server Anda.
      • Apache yang terinstal dengan mengikuti Cara Menginstal Apache pada Ubuntu 20.04. Pastikan Anda memiliki berkas hos virtual untuk domain Anda. Tutorial ini akan menggunakann /etc/apache2/sites-available/your_domain.conf sebagai contoh.

      Langkah 1 — Menginstal Certbot

      Untuk memperoleh sertifikat SSL dengan Let’s Encrypt, kita perlu menginstal perangkat lunak Certbot pada server Anda terlebih dahulu. Kita akan menggunakan repositori paket Ubuntu asali untuk itu.

      Kita membutuhkan dua paket: certbot dan python3-certbot-apache. Paket yang disebut terakhir adalah plugin yang mengintegrasikan Certbot dengan Apache, yang memungkinkan kita untuk mengotomatiskan perolehan sertifikat dan mengonfigurasi HTTPS di dalam server web Anda dengan satu perintah.

      • sudo apt install certbot python3-certbot-apache

      Anda juga akan diminta mengonfirmasi instalasi dengan menekan Y, lalu ENTER.

      Certbot sekarang telah terinstal di server Anda. Pada langkah selanjutnya, kita akan memverifikasi konfigurasi Apache untuk memastikan hos virtual Anda telah disiapkan dengan benar. Ini akan memastikan bahwa skrip klien certbot akan mampu mendeteksi domain Anda dan mengonfigurasi ulang server web Anda untuk menggunakan sertifikat SSL yang baru saja dihasilkan secara otomatis.

      Langkah 2 — Memeriksa Konfigurasi Hos Virtual Apache Anda

      Agar dapat memperoleh dan mengonfigurasi SSL untuk server web Anda secara otomatis, Certbot perlu menemukan hos virtual yang benar yang ada di dalam berkas konfigurasi Apache Anda. Nama (atau nama-nama) domain server Anda akan diambil dari arahan ServerName dan ServerAlias yang ditetapkan di dalam blok konfigurasi VirtualHost Anda.

      Jika Anda mengikuti langkah penyiapan hos virtual dalam tutorial instalasi Apache, Anda harusnya memiliki blok VirtualHost yang disiapkan untuk domain Anda di /etc/apache2/sites-available/your_domain.conf dengan arahan ServerName dan juga ServerAlias yang sudah diatur dengan benar.

      Untuk memeriksa ini, buka berkas hos virtual untuk domain Anda dengan menggunakan nano atau editor teks yang Anda sukai:

      • sudo nano /etc/apache2/sites-available/your_domain.conf

      Temukan baris ServerName dan ServerAlias yang sudah ada. Baris itu akan terlihat seperti ini:

      /etc/apache2/sites-available/your_domain.conf

      ...
      ServerName your_domain
      ServerAlias www.your_domain
      ...
      

      Jika Anda telah menyiapkan ServerName dan ServerAlias seperti ini, Anda dapat keluar dari editor teks Anda dan melanjutkan ke langkah selanjutnya. Jika Anda menggunakan nano, Anda dapat keluar dengan mengetik CTRL+X, lalu Y, dan ENTER untuk mengonfirmasi.

      Jika konfigurasi hos virtual Anda saat ini tidak sesuai dengan contoh, perbaruilah supaya sesuai contoh. Setelah Anda selesai, simpan berkas itu dan keluar dari editor. Lalu, jalankan perintah berikut untuk memvalidasi perubahan Anda:

      • sudo apache2ctl configtest

      Anda akan mendapat pesan Syntax OK sebagai respons. Jika Anda mendapat pesan kesalahan, buka kembali berkas host virtual dan periksa adanya kesalahan tik atau karakter yang hilang. Setelah sintaks berkas konfigurasi Anda benar, muat ulang Apache supaya perubahan itu diterapkan:

      • sudo systemctl reload apache2

      Dengan perubahan ini, Certbot akan dapat menemukan blok VirtualHost yang benar dan memperbaruinya.

      Selanjutnya, mari kita perbarui firewall untuk mengizinkan lalu lintas HTTPS.

      Langkah 3 — Mengizinkan HTTPS Melewati Firewall

      Jika firewall UFW Anda sudah diaktifkan, seperti yang disarankan oleh panduan prasyarat, Anda perlu menyesuaikan pengaturan untuk mengizinkan lalu lintas HTTPS. Setelah instalasi, Apache mendaftarkan beberapa profil aplikasi UFW yang berbeda. Kita dapat memanfaatkan profil Apache Full untuk mengizinkan baik lalu lintas HTTP dan HTTPS pada server Anda.

      Untuk memverifikasi lalu lintas seperti apa yang diizinkan pada server Anda, Anda dapat menggunakan:

      Jika Anda telah mengikuti salah satu panduan instalasi Apache kami, keluaran Anda akan terlihat seperti ini, yang berarti bahwa hanya lalu lintas HTTP pada porta 80 yang diizinkan untuk saat ini:

      Output

      Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Apache ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Apache (v6) ALLOW Anywhere (v6)

      Untuk menambah lalu lintas HTTPS masuk, izinkan profil “Apache Full” dan hapus profil “Apache” yang lewah lainnya:

      • sudo ufw allow 'Apache Full'
      • sudo ufw delete allow 'Apache'

      Status Anda sekarang akan terlihat seperti ini:

      Output

      Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere Apache Full ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Apache Full (v6) ALLOW Anywhere (v6)

      Anda sekarang siap untuk menjalankan Certbot dan memperoleh sertifikat Anda.

      Langkah 4 — Memperoleh Sertifikat SSL

      Certbot menyediakan berbagai cara untuk memperoleh sertifikat SSL melalui plugin. Plugin Apache akan menangani konfigurasi ulang Apache dan memuat ulang konfigurasi itu ketika diperlukan. Untuk menggunakan plugin ini, ketik yang berikut:

      Skrip ini akan meminta Anda menjawab serangkaian pertanyaan untuk mengonfigurasi sertifikat SSL Anda. Pertama, skrip ini akan meminta alamat surel Anda yang valid. Surel ini akan digunakan untuk pemberitahuan pembaruan dan keamanan:

      Output

      Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): you@your_domain

      Setelah menyediakan alamat surel yang valid, tekan ENTER untuk melanjutkan ke langkah selanjutnya. Anda kemudian akan diminta mengonfirmasi apakah Anda menyetujui ketentuan layanan dari Let’s Encrypt. Anda dapat mengonfirmasi dengan menekan A lalu ENTER:

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

      Selanjutnya, Anda akan ditanya apakah mau membagi surel Anda dengan Electronic Frontier Foundation untuk menerima berita dan informasi lainnya. Jika Anda tidak ingin berlangganan konten mereka, ketik N. Jika Anda mau, ketik Y. Lalu, tekan ENTER untuk melanjutkan ke langkah selanjutnya.

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

      Langkah selanjutnya akan meminta Anda untuk menginformasikan Certbot terkait Anda ingin mengaktifkan HTTPS untuk domain yang mana. Nama-nama domain yang terdaftar secara otomatis diperoleh dari konfigurasi hos virtual Apache Anda, itu sebabnya penting untuk memastikan bahwa Anda memiliki pengaturan ServerName dan ServerAlias yang dikonfigurasi dengan benar di dalam hos virtual Anda. Jika Anda ingin mengaktifkan HTTPS untuk semua nama domain yang terdaftar (disarankan), Anda dapat mengosongkan prompt itu dan tekan ENTER untuk melanjutkan. Jika tidak, pilih domain yang Anda ingin aktifkan HTTPS-nya dengan membuat daftar dari setiap nomor yang sesuai, yang dipisahkan dengan koma dan/atau spasi, lalu tekan ENTER.

      Which names would you like to activate HTTPS for?
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      1: your_domain
      2: www.your_domain
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Select the appropriate numbers separated by commas and/or spaces, or leave input
      blank to select all options shown (Enter 'c' to cancel):
      

      Anda akan melihat keluaran seperti ini:

      Obtaining a new certificate
      Performing the following challenges:
      http-01 challenge for your_domain
      http-01 challenge for www.your_domain
      Enabled Apache rewrite module
      Waiting for verification...
      Cleaning up challenges
      Created an SSL vhost at /etc/apache2/sites-available/your_domain-le-ssl.conf
      Enabled Apache socache_shmcb module
      Enabled Apache ssl module
      Deploying Certificate to VirtualHost /etc/apache2/sites-available/your_domain-le-ssl.conf
      Enabling available site: /etc/apache2/sites-available/your_domain-le-ssl.conf
      Deploying Certificate to VirtualHost /etc/apache2/sites-available/your_domain-le-ssl.conf
      

      Selanjutnya, Anda akan diminta memilih apakah Anda ingin lalu lintas HTTP dialihkan ke HTTPS atau tidak. Dalam praktiknya, itu berarti saat seseorang mengunjungi situs web Anda melalui saluran yang tidak terenkripsi (HTTP), dia akan secara otomatis dialihkan ke alamat HTTPS dari situs web Anda. Pilih 2 untuk mengaktifkan pengalihan, atau 1 jika Anda ingin mempertahankan baik HTTP dan HTTPS sebagai metode yang terpisah untuk mengakses situs web Anda.

      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
      
      

      Setelah langkah ini, konfigurasi Certbot selesai, dan Anda akan melihat catatan terakhir tentang sertifikat baru Anda, di mana Anda dapat menemukan berkas yang dihasilkan, dan bagaimana cara menguji konfigurasi Anda dengan menggunakan alat eksternal yang menganalisis keaslian sertifikat Anda:

      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      Congratulations! You have successfully enabled https://your_domain and
      https://www.your_domain
      
      You should test your configuration at:
      https://www.ssllabs.com/ssltest/analyze.html?d=your_domain
      https://www.ssllabs.com/ssltest/analyze.html?d=www.your_domain
      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
      
      IMPORTANT NOTES:
       - Congratulations! Your certificate and chain have been saved at:
         /etc/letsencrypt/live/your_domain/fullchain.pem
         Your key file has been saved at:
         /etc/letsencrypt/live/your_domain/privkey.pem
         Your cert will expire on 2020-07-27. 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"
       - 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
      
      

      Sertifikat Anda sekarang sudah terinstal dan dimuat ke konfigurasi Apache. Coba muat ulang situs Anda dengan menggunakan https:// dan perhatikan indikator keamanan di peramban Anda. Peramban akan menunjukkan bahwa situs Anda sudah diamankan dengan benar, biasanya dengan adanya ikon kunci di dalam bilah alamat.

      Anda dapat menggunakan SSL Labs Server Test untuk memverifikasi nilai sertifikat Anda dan memperoleh informasi mendetail tentang hal itu, dari sudut pandang layanan eksternal.

      Di langkah selanjutnya yang juga merupakan langkah terakhir, kita akan menguji fitur pembaruan otomatis Certbot, yang menjamin bahwa sertifikat Anda akan diperbarui secara otomatis sebelum tanggal kedaluwarsa.

      Langkah 5 — Memverifikasi Pembaruan Otomatis Certbot

      Sertifikat Let’s Encrypt hanya berlaku selama 90 hari. Kebijakan ini diterapkan untuk mendorong pengguna supaya mengotomatiskan proses pembaruan sertifikatnya, serta memastikan bahwa sertifikat yang disalahgunakan atau kunci yang dicari akan kedaluwarsa lebih cepat daripada seharusnya.

      Paket certbot yang kita instal menangani pembaruan dengan memasukkan skrip pembaruan ke /etc/cron.d, yang dikelola oleh layanan systemctl yang bernama certbot.timer. Skrip ini berjalan dua kali sehari dan secara otomatis memperbarui sertifikat apa pun yang berada dalam waktu 30 hari dari tanggal kedaluwarsa.

      Untuk memeriksa status layanan ini dan memastikan bahwa layanan sudah aktif dan berjalan, Anda dapat menggunakan:

      • sudo systemctl status certbot.timer

      Anda akan medapat keluaran yang mirip dengan ini:

      Output

      ● certbot.timer - Run certbot twice daily Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled) Active: active (waiting) since Tue 2020-04-28 17:57:48 UTC; 17h ago Trigger: Wed 2020-04-29 23:50:31 UTC; 12h left Triggers: ● certbot.service Apr 28 17:57:48 fine-turtle systemd[1]: Started Run certbot twice daily.

      Untuk menguji proses pembaruan, Anda dapat melakukan uji coba dengan certbot:

      • sudo certbot renew --dry-run

      Jika Anda tidak melihat kesalahan, maka Anda sudah siap. Ketika diperlukan, Certbot akan memperbarui sertifikat Anda dan memuat ulang Apache untuk menerapkan perubahan itu. Jika proses pembaruan otomatis itu terus-menerus gagal, Let’s Encrypt akan mengirim pesan ke surel yang Anda tentukan, memperingatkan Anda saat sertifikat Anda akan berakhir.

      Kesimpulan

      Dalam tutorial ini, Anda telah menginstal certbot klien Let’s Encrypt, mengonfigurasi dan menginstal sertifikat SSL untuk domain Anda, dan mengonfirmasi bahwa layanan pembaruan otomatis Certbot sudah aktif di dalam systemctl. Jika Anda memiliki pertanyaan lebih lanjut tentang cara menggunakan Certbot, dokumentasi mereka adalah tempat yang baik untuk memulai.



      Source link