{"id":6840,"date":"2022-11-27T12:22:10","date_gmt":"2022-11-27T12:22:10","guid":{"rendered":"https:\/\/davelevy.info\/wiki\/?p=6840"},"modified":"2025-07-22T23:22:17","modified_gmt":"2025-07-22T23:22:17","slug":"ssl-on-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/davelevy.info\/wiki\/ssl-on-a-raspberry-pi\/","title":{"rendered":"SSL on a Raspberry Pi"},"content":{"rendered":"\n<p>Installing an SSL certificate and enabling https was a faff, here are my notes. Now including postfix and dovecot&#8230;<br><\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Firstly, my DNS provider is NOIP, and I chose to get a TrustCOR certificate through their portal. Their free service offers a single certificate as a bundled feature.<\/p>\n\n\n\n<p>Basically, the process is in three parts, get a certificate, configure apache, &amp; configure the firewall.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The NOIP Portal<\/h3>\n\n\n\n<p>Go to &#8220;My Services &gt; SSL Certificates&#8221;, there are four help pages, <a href=\"https:\/\/www.noip.com\/support\/knowledgebase\/how-do-i-create-a-csr-for-my-ssl-certificate\/\">generate a CSR<\/a>, which pointed my at &#8220;<a href=\"https:\/\/www.noip.com\/support\/knowledgebase\/apache-openssl\/\">Apache OpenSSL<\/a>&#8220;; read this all and note that the Country code of where I live is GB not UK and they require a state\/province field. This use of <code>openssl<\/code> generates the private key. The installation guide is at <a href=\"https:\/\/trustcor.com\/support\/ssl-install\/apache-ssl-installation.php\">apache-ssl-installation<\/a>, wish I&#8217;d read it thoroughly, although at Apache 2.4.8, it is no longer necessary to separately define the &#8216;chain&#8217; file. The portal offers a feature to down load the certificate, do so and <code>copy to \/etc\/ssl\/certs<\/code>.<\/p>\n\n\n\n<p>I installed a new cert in 2024, it was much easier, see the comment dated Feb 2024. Download it, copy to the .\/certs folder and then ensure the apache config file points at it. The issuer <a href=\"https:\/\/www.digicert.com\/kb\/ssl-certificate-installation.htm\">documents the process here<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Server<\/h3>\n\n\n\n<p>Firstly,<code> mod_ssl<\/code> and <code>apache2<\/code> are already installed, this can be checked with both apt and <code>ls \/etc\/apache\/mods-available<\/code>. This guide assumes you have certificate chain file, I had a .pem file and that this is issued by a CA and that you have its private key.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The mod needs to be enabled <code>a2enmod ssl<\/code>. This creates a default ssl conf file in .\/sites-available.<\/li>\n\n\n\n<li>The SSL .conf file needs to be edited. This is in the <code>.\/sites-available<\/code>, and it was created by the enable mod command i.e. <code>a2enmod ssl<\/code> ; its name is <code>000-default-ssl.conf<\/code> but ideally make a copy and change the basename. i.e. <code>cp default-ssl.conf mydns.conf<\/code><\/li>\n\n\n\n<li>Then edit <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/ssl\/ssl_howto.html\">the two keyfile parameters<\/a>, use the .pem-chain and .key. The version of Apache I have (2.4.8) does not require the separate declaration of the chain file.<\/li>\n\n\n\n<li>My initial parameters are now set to, <code>Listen 433; &lt;VirtualHost *:433&gt;; ServerName ${InternetName}<\/code><\/li>\n\n\n\n<li><code>a2ensite $(basename ${conf.file})<\/code> enables the site, note that <code>a2dissite<\/code> disables it if necessary.<\/li>\n\n\n\n<li>the hostname needs to match the hostname declared to the certificate, edit <code>\/etc\/hosts<\/code> and <code>\/etc\/hostname<\/code><\/li>\n\n\n\n<li>then <code>systemctl reload apache2<\/code> and <code>systemctl restart apache2<\/code> for good measure<\/li>\n\n\n\n<li>I was having problems getting it to work, because https was prohibited at the boundary,&nbsp; and so I ran <code>hostname <\/code>to change the hostname and put the FQDN into the hosts file. I am thus unsure if this and the ServerName parameter is required. This may break something else.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Firewall<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>I use a BT HomeHub (5A) and it needed an https rule to be set because I had not set one before. Not doing this first, probably cost me days.<\/li>\n<\/ol>\n\n\n\n<p>See also <a href=\"https:\/\/davelevy.info\/wiki\/raspberry-pi-iii\/#comment-148525\">https:\/\/davelevy.info\/wiki\/raspberry-pi-iii\/#comment-148525<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Postfix &amp; Dovecot<\/h3>\n\n\n\n<p>These notes were generated by Google AI Perspectives.<\/p>\n\n\n\n<p>To secure Postfix email server on Raspbian with SSL\/TLS, you&#8217;ll need to generate or obtain an SSL\/TLS certificate, configure Postfix to use it, and verify the setup. This involves editing the Postfix main.cf file, setting up the necessary paths for the certificate and key, and potentially configuring Dovecot for secure email access.&nbsp;<\/p>\n\n\n\n<p>1. Generating or Obtaining an SSL\/TLS Certificate:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Self-Signed Certificates:<\/strong><\/li>\n<\/ul>\n\n\n\n<p>You can generate your own self-signed certificates using openssl on your Raspberry Pi. This is a simple option for local testing or private use but might not be trusted by clients.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Third-Party Certificate Authorities (CAs):<\/strong><\/li>\n<\/ul>\n\n\n\n<p>For production environments, obtain a certificate from a reputable CA like Let&#8217;s Encrypt. This will allow clients to trust your server.&nbsp;<\/p>\n\n\n\n<p><strong>Steps for Self-Signed Certificates (Simplified):<\/strong><\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Install openssl:<\/li>\n<\/ol>\n\n\n\n<p>sudo apt-get install openssl.&nbsp;<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Generate a key:<\/li>\n<\/ol>\n\n\n\n<p>sudo openssl genrsa -out \/etc\/postfix\/ssl\/key.pem 2048.&nbsp;<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Create a certificate signing request (CSR):<\/li>\n<\/ol>\n\n\n\n<p>sudo openssl req -new -key \/etc\/postfix\/ssl\/key.pem -out \/etc\/postfix\/ssl\/cert.csr.&nbsp;<\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Create a self-signed certificate:<\/li>\n<\/ol>\n\n\n\n<p>sudo openssl x509 -req -days 365 -in \/etc\/postfix\/ssl\/cert.csr -signkey \/etc\/postfix\/ssl\/key.pem -out \/etc\/postfix\/ssl\/cert.pem.&nbsp;<\/p>\n\n\n\n<p>2. Configuring Postfix for SSL\/TLS:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Edit main.cf:\n<ul class=\"wp-block-list\">\n<li>Open the file: sudo nano \/etc\/postfix\/main.cf.<\/li>\n\n\n\n<li>Set these options:\n<ul class=\"wp-block-list\">\n<li>smtpd_tls_cert_file=\/etc\/postfix\/ssl\/cert.pem.<\/li>\n\n\n\n<li>smtpd_tls_key_file=\/etc\/postfix\/ssl\/key.pem.<\/li>\n\n\n\n<li>smtpd_tls_CA_file=\/etc\/postfix\/ssl\/ca.pem (if using a CA certificate).<\/li>\n\n\n\n<li>smtpd_use_tls=yes.<\/li>\n\n\n\n<li>smtpd_tls_security_level=encrypt.<\/li>\n\n\n\n<li>smtpd_tls_loglevel=1 (optional, for debugging).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Save the file and exit.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Restart Postfix:<\/strong> sudo systemctl restart postfix.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>3. Verifying SSL\/TLS Configuration:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Test with a tool like openssl s_client:<\/li>\n<\/ul>\n\n\n\n<p>&nbsp;sudo openssl s_client -starttls smtp -connect [your_server_ip_or_hostname]:587 -showcerts -debug<\/p>\n\n\n\n<p>Replace [your_server_ip_or_hostname] with your server&#8217;s IP address or domain name.<\/p>\n\n\n\n<p>The output should show the certificate information and confirm a successful TLS connection.&nbsp;<\/p>\n\n\n\n<p>4. (Optional) Configuring Dovecot for Secure Email Access:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>If using Dovecot:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Modify the Dovecot configuration (\/etc\/dovecot\/dovecot.conf).<\/li>\n\n\n\n<li>Set ssl = yes and ssl_cert = \/etc\/postfix\/ssl\/cert.pem (or the appropriate path).<\/li>\n\n\n\n<li>Restart Dovecot: sudo systemctl restart dovecot<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Help<\/h3>\n\n\n\n<p>I found these sites helpful<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><a href=\"https:\/\/variax.wordpress.com\/2017\/03\/18\/adding-https-to-the-raspberry-pi-apache-web-server\/comment-page-1\/\">Adding https to the raspberry pi apache web server<\/a> from variax.wordpress.com, uses local certs, but documents making a key pair using openssl and the changes needed in the .conf file and <a href=\"https:\/\/towardsdatascience.com\/how-to-host-multiple-website-with-apache-virtual-hosts-4423bd0aefbf\">How to Host Multiple Websites with Apache Virtual Hosts<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.linode.com\/docs\/guides\/how-to-enable-disable-website\/\">How to enable\/disable a website<\/a> from linode.com, talks about the conf file and a2 commands, also <a href=\"https:\/\/ubiq.co\/tech-blog\/enable-mod_ssl-apache\/\">enable mod_ssl apache<\/a> on the commands, mainly <code>systemctl<\/code>, from ubiq.co, but also <a href=\"https:\/\/devdojo.com\/serverenthusiast\/14-apache-commands-to-help-you-manage-your-server-like-a-pro\">14 apache commands to help you manage your server like apro<\/a> from devdojo which also documents the commands and has more than ubiq\u2019s<\/li>\n\n\n\n<li>Here\u2019s YAF page, <a href=\"https:\/\/www.ssls.com\/knowledgebase\/how-to-install-an-ssl-certificate-on-apache\/\">How to install an SSL certificate on apache&nbsp; <\/a>from www.ssls.com.<\/li>\n\n\n\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/46819390\/apache-loads-mod-ssl-but-ifmodule-mod-ssl-c-ignored-in-my-vhosts\">Apache loads mod_ssl but ifmodule mod_ssl.c ignored in my vhosts<\/a> from stackoverflow, the order of the include statements is important, but was not relevant to me.<\/li>\n\n\n\n<li>An<a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/vhosts\/examples.html\"> example vhosts file from Apache<\/a>, and&nbsp; <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/ssl\/ssl_howto.html\">a how to<\/a>, again from Apache, both major on the .conf file settings.<\/li>\n\n\n\n<li>and <a href=\"https:\/\/raspberrytips.com\/set-new-hostname-raspberry-pi\/\">Set new hostname raspberry pi\/<\/a> which points at raspi-config.<\/li>\n\n\n\n<li>A page on <a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/rewrite\/remapping.html\">Remapping<\/a> at apache,com was used to redirect port 80 to the https port, I needed a CNAME in dns to redirect the standby name<\/li>\n\n\n\n<li><a href=\"https:\/\/linux.die.net\/man\/1\/openssl\">man openssl<\/a> from linux.die.net how to make the key pair.<\/li>\n\n\n\n<li><a href=\"https:\/\/forums.raspberrypi.com\/viewtopic.php?t=210084\">Simple Email Configuration on a Raspberry Pi<\/a> from the Raspberry Pi forums<\/li>\n\n\n\n<li><a href=\"https:\/\/medium.com\/20ms\/configuring-ssl-tls-for-postfix-5c87cb54aa89\">Configuring SSL tls for postfix<\/a> on Medium<\/li>\n\n\n\n<li><a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-a-firewall-with-ufw-on-ubuntu#step-4-enabling-ufw\">Using UFW <\/a>from digital ocean.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Installing an SSL certificate and enabling https was a faff, here are my notes. Now including postfix and dovecot&#8230;<\/p>\n","protected":false},"author":1,"featured_media":6777,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_share_on_mastodon":"0"},"categories":[6,3],"tags":[77,1274,54,1299,914,1862,994,1286,1300,911,1863],"class_list":["post-6840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-networking","category-technology","tag-apache","tag-how-to","tag-howto","tag-https","tag-networking","tag-noip","tag-raspberry-pi","tag-raspbian","tag-ssl","tag-technology","tag-trustcor"],"share_on_mastodon":{"url":"https:\/\/mastodon.social\/@davelevy_eu\/111958313963131687","error":""},"jetpack_featured_media_url":"https:\/\/davelevy.info\/wiki\/wp-content\/uploads\/2022\/10\/raspberrytart-unsplash-alexandrakusper-cropped-w1024.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/6840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/comments?post=6840"}],"version-history":[{"count":6,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/6840\/revisions"}],"predecessor-version":[{"id":12656,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/posts\/6840\/revisions\/12656"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media\/6777"}],"wp:attachment":[{"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/media?parent=6840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/categories?post=6840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/davelevy.info\/wiki\/wp-json\/wp\/v2\/tags?post=6840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}