{"id":854,"date":"2018-10-07T21:35:48","date_gmt":"2018-10-07T18:35:48","guid":{"rendered":"http:\/\/kifarunix.com\/?p=854"},"modified":"2024-03-11T20:09:58","modified_gmt":"2024-03-11T17:09:58","slug":"how-to-create-self-signed-ssl-certificate-with-mkcert-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-create-self-signed-ssl-certificate-with-mkcert-on-ubuntu-18-04\/","title":{"rendered":"Create Locally Trusted SSL Certificates with mkcert on Ubuntu 18.04"},"content":{"rendered":"\n<p>Hello folks, welcome to this very tutorial on how to create&nbsp;<span class=\"st\">locally trusted SSL certificates<\/span> with mkcert on Ubuntu 18.04. <strong><a href=\"https:\/\/mkcert.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">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<h2 class=\"wp-block-heading\">Creating Locally Trusted SSL Certificates with mkcert<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Installing mkcert on Ubuntu<\/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<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<\/h3>\n\n\n\n<p>Now that the mkcert utility is installed, run the command below to generate your local CA.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mkcert -install<\/code><\/pre>\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 root CA is stored under <strong>#HOME\/.local\/share\/mkcert<\/strong>. <\/p>\n\n\n\n<p>You can print the location directory of the root CA path by running the command below.<\/p>\n\n\n\n<pre id=\"block-af3d8a68-b047-4394-870a-f863598baeec\" class=\"wp-block-preformatted\">mkcert -CAROOT<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/home\/amos\/.local\/share\/mkcert<\/code><\/pre>\n\n\n\n<p>If you encounter the error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ERROR: no Firefox and\/or Chrome\/Chromium security databases found<\/code><\/pre>\n\n\n\n<p>Just launch the browsers and re-run the install command.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating 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<p>Sample command output;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nCreated 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\n<\/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 18.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=\"scroll-box\"><code>\nserver {\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}\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<\/code><\/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 create locally trusted SSL certificates with mkcert on Ubuntu 18.04.<\/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<h2 class=\"wp-block-heading\">Other Tutorials<\/h2>\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>Hello folks, welcome to this very tutorial on how to create&nbsp;locally trusted SSL certificates with mkcert on Ubuntu 18.04. mkcert is a simple zero-config tool<\/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,159,1187],"tags":[6678,3600,160,166,6679,3607,167,165],"class_list":["post-854","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-security","category-encryption","category-ssl-tls","tag-create-self-signed-ssl-certs-with-mkcert","tag-create-ssl-with-mkcert","tag-encryption","tag-https","tag-install-mkcert-on-ubuntu-linux","tag-locally-trusted-ssl-with-mkcert","tag-mkcert","tag-ssl","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\/854"}],"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=854"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":21043,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/854\/revisions\/21043"}],"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=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}