{"id":8948,"date":"2021-05-31T23:16:59","date_gmt":"2021-05-31T20:16:59","guid":{"rendered":"https:\/\/kifarunix.com\/?p=8948"},"modified":"2024-03-18T22:17:52","modified_gmt":"2024-03-18T19:17:52","slug":"create-locally-trusted-ssl-certificates-with-mkcert-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/create-locally-trusted-ssl-certificates-with-mkcert-on-ubuntu-20-04\/","title":{"rendered":"Create Locally Trusted SSL Certificates with mkcert on Ubuntu 20.04"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to create&nbsp;<span class=\"st\">locally trusted SSL certificates<\/span> with mkcert on Ubuntu 20.04. <strong><a href=\"https:\/\/github.com\/FiloSottile\/mkcert\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">mkcert<\/a><\/strong> is a<span class=\"text-gray-dark mr-2\"> simple zero-config tool that is used to make locally trusted development certificates. It <\/span>automatically creates and installs a local CA in the system root store, and generates locally-trusted certificates.<\/p>\n\n\n\n<p>Using certificates from real certificate authorities (CAs) for development can be dangerous or impossible (for hosts like <code>localhost<\/code> or <code>127.0.0.1<\/code>), but self-signed certificates cause trust errors. Managing your own CA is the best solution, but usually involves arcane commands, specialized knowledge and manual steps, but not any more with the availability of mkcert utility.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Using mkcert to Create Locally Trusted SSL Certificates<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Install Certutil on Ubuntu 20.04<\/h3>\n\n\n\n<p>As a prerequisite, you are required to install <strong>certutil<\/strong>, <span class=\"st\"> a command-line utility that can create and modify certificate and key databases before you can install mkcert utility.<\/span><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo apt install libnss3-tools -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Installing mkcert on Ubuntu 20.04<\/h3>\n\n\n\n<p>Once the installation of certutil is done, download the current version of mkcert pre-built binary from <a href=\"https:\/\/github.com\/FiloSottile\/mkcert\/releases\" target=\"_blank\" rel=\"noopener\">Github releases page<\/a>.<\/p>\n\n\n\n<p>As of this writing, the current version of mkcert is v1.4.3<\/p>\n\n\n\n<p>So download the current version and install it as shown below<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget https:\/\/github.com\/FiloSottile\/mkcert\/releases\/download\/v1.4.3\/mkcert-v1.4.3-linux-amd64<\/code><\/pre>\n\n\n\n<pre id=\"block-eeb9f97c-47eb-45cd-8792-0fcad28c61f0\" class=\"wp-block-preformatted\">sudo cp mkcert-v1.4.3-linux-amd64 \/usr\/local\/bin\/mkcert<\/code><\/pre>\n\n\n\n<pre id=\"block-acf8b835-8c54-4feb-b2a7-aba0976b9a3f\" class=\"wp-block-preformatted\">sudo chmod +x \/usr\/local\/bin\/mkcert<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Generate Local CA on Ubuntu 20.04<\/h3>\n\n\n\n<p>Now that the mkcert utility is installed, run the command below to generate and install your local CA on Ubuntu 20.04.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkcert -install<\/code><\/pre>\n\n\n\n<p>Sample command output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The local CA is now installed in the system trust store! \u26a1\ufe0f\nThe local CA is now installed in the Firefox and\/or Chrome\/Chromium trust store (requires browser restart)! \ud83e\udd8a<\/code><\/pre>\n\n\n\n<p>The command creates a root CA and is stored under <strong>~\/.local\/share\/mkcert<\/strong>.<\/p>\n\n\n\n<p>You can find the root CA path by running the command below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkcert -CAROOT<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home\/koromicha\/.local\/share\/mkcert<\/code><\/pre>\n\n\n\n<p>Listing the directory contents;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls -1 ~\/.local\/share\/mkcert<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>rootCA-key.pem\nrootCA.pem<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Create Locally Trusted SSL Certificates with mkcert<\/h3>\n\n\n\n<p>Now that you have your local CA, run the command below to generate local SSL certificates using mkcert command.<\/p>\n\n\n\n<pre id=\"block-84733f17-a9de-430b-9a8a-a6903a7f3fe1\" class=\"wp-block-preformatted\">mkcert kifarunix-demo.com '*.kifarunix-demo.com' localhost 127.0.0.1 ::1<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>Sample command output;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Created a new certificate valid for the following names \ud83d\udcdc\n - \"kifarunix-demo.com\"\n - \"*.kifarunix-demo.com\"\n - \"localhost\"\n - \"127.0.0.1\"\n - \"::1\"\n\nReminder: X.509 wildcards only go one level deep, so this won't match a.b.kifarunix-demo.com \u2139\ufe0f\n\nThe certificate is at \".\/kifarunix-demo.com+4.pem\" and the key at \".\/kifarunix-demo.com+4-key.pem\" \u2705\n\nIt will expire on 31 August 2023 \ud83d\uddd3<\/code><\/pre>\n\n\n\n<p>You have the certificate and key in the current working directory;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls -1 .\/kifarunix-demo.com+*<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> .\/kifarunix-demo.com+4-key.pem\n .\/kifarunix-demo.com+4.pem<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Web Server HTTPS using the Certificates<\/h3>\n\n\n\n<p>The certificates are now installed and it is time to enable your webserver to use them for HTTPS connections.<\/p>\n\n\n\n<p>To configure Apache to use these certificates, edit the default ssl configuration file, <strong>\/etc\/apache2\/sites-available\/default-ssl.conf<\/strong> and change the SSL certificate and key file to point to the locally generated cert and key file above.<\/p>\n\n\n\n<p>See the example below. Note the certificates are in my home directory. <\/p>\n\n\n\n<p><strong>Be sure to replace the paths accordingly.<\/strong><\/p>\n\n\n\n<pre id=\"block-380c4449-7129-4bb4-b4c6-7ec6ad58d5d4\" class=\"wp-block-preformatted\">sudo sed -i 's#\/etc\/ssl\/certs\/ssl-cert-snakeoil.pem#\/home\/koromicha\/kifarunix-demo.com+4.pem#; s#\/etc\/ssl\/private\/ssl-cert-snakeoil.key#\/home\/koromicha\/kifarunix-demo.com+4-key.pem#' \/etc\/apache2\/sites-available\/default-ssl.conf<\/code><\/pre>\n\n\n\n<p>To verify this;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>grep -E \"SSLCertificateFile|SSLCertificateKeyFile\" \/etc\/apache2\/sites-available\/default-ssl.conf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\t\t#   SSLCertificateFile directive is needed.\n\t\tSSLCertificateFile\t\/home\/koromicha\/kifarunix-demo.com+4.pem\n\t\tSSLCertificateKeyFile \/home\/koromicha\/kifarunix-demo.com+4-key.pem\n\t\t#   the referenced file can be the same as SSLCertificateFile<\/code><\/pre>\n\n\n\n<p>Enable Apache to use SSL by loading the ssl modules;<\/p>\n\n\n\n<pre id=\"block-65d454ec-d4ea-44ab-a3d1-d305d3be6ffd\" class=\"wp-block-preformatted\">sudo a2enmod ssl<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo a2ensite default-ssl.conf<\/code><\/pre>\n\n\n\n<p>Reload and restart Apache to activate the new configuration<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo systemctl restart apache2<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify Local SSL Certs generated with mkcert<\/h3>\n\n\n\n<p>Navigate to the browser and try to access your domain.<\/p>\n\n\n\n<p>I am using local hosts file for my DNS entries.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"381\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/05\/mkcert-valid-ssl.png\" alt=\"Create Locally Trusted SSL Certificates with mkcert on Ubuntu 20.04\" class=\"wp-image-8950\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/05\/mkcert-valid-ssl.png?v=1622490794 902w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/05\/mkcert-valid-ssl-768x324.png?v=1622490794 768w\" sizes=\"(max-width: 902px) 100vw, 902px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Enable the Certificates for Nginx Web Server<\/h3>\n\n\n\n<p>Create your web page configuration as shown below.<\/p>\n\n\n\n<p><strong>Replace the paths to the ceritificate and key accordingly<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/nginx\/sites-available\/example.com<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>server {\nlisten 80;\nlisten 443 ssl;\n\nssl on;\nssl_certificate <strong>\/home\/koromicha\/kifarunix-demo.com+4.pem<\/strong>; \nssl_certificate_key <strong>\/home\/koromicha\/kifarunix-demo.com+4-key.pem<\/strong>;\n\nserver_name example.com;\nlocation \/ {\nroot \/var\/www\/html\/example;\nindex index.html;\n}\n}<\/code><\/pre>\n\n\n\n<p>Verify that the configuration has no error.<\/p>\n\n\n\n<pre id=\"block-1b061e53-2a4f-4b56-951c-9f1f20ab103d\" class=\"wp-block-preformatted\">nginx -t<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n\n\n\n<p>Restart Nginx<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart nginx<\/code><\/pre>\n\n\n\n<p>Navigate to the browser and test your ssl for your domain.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1017\" height=\"385\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/05\/localhost-https-mkcert.png\" alt=\"\" class=\"wp-image-8951\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/05\/localhost-https-mkcert.png?v=1622490840 1017w, https:\/\/kifarunix.com\/wp-content\/uploads\/2021\/05\/localhost-https-mkcert-768x291.png?v=1622490840 768w\" sizes=\"(max-width: 1017px) 100vw, 1017px\" \/><\/figure>\n\n\n\n<p>Well, seems up-to that far everything is fine.<\/p>\n\n\n\n<p>And that concludes our guide on how to use mkcert to create locally trusted SSL certificates.<\/p>\n\n\n\n<p>More <code><strong>mkcert<\/strong><\/code> usage information.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkcert --help<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-nginx-with-ssl-tls-certificates-on-centos-8\/\">Configure Nginx with SSL\/TLS certificates on CentOS 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-ssl-tls-certificate-expiry-with-prometheus-and-grafana\/\">Monitor SSL\/TLS Certificate Expiry with Prometheus and Grafana<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-apache-with-ssl-tls-certificates-on-centos-8\/\">Configure Apache with SSL\/TLS Certificates on CentOS 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/easy-way-to-configure-filebeat-logstash-ssl-tls-connection\/\">Easy way to configure Filebeat-Logstash SSL\/TLS Connection<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to create&nbsp;locally trusted SSL certificates with mkcert on Ubuntu 20.04. mkcert is a simple zero-config tool that is<\/p>\n","protected":false},"author":1,"featured_media":8955,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[34,121,1187],"tags":[3600,3604,3602,167,3605,3606,3601,943,3603],"class_list":["post-8948","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-howtos","category-ssl-tls","tag-create-ssl-with-mkcert","tag-install-mkcert","tag-local-ssl-with-mkcert","tag-mkcert","tag-mkcert-ca","tag-mkcert-ssl","tag-mkcert-ubuntu","tag-ssl-tls","tag-trusted-ssl-with-mkcert","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8948"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=8948"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8948\/revisions"}],"predecessor-version":[{"id":21804,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8948\/revisions\/21804"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/8955"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}