Because email is such a crucial part of modern day communication, it’s important to keep security in mind for all parts of your email pipeline. Roundcube is a webmail client with strong security features and extensive customization options from its plugin repository. This article explains how to further secure a basic, existing Roundcube installation.
If you used SSL when configuring your IMAP and STMP settings in Roundcube’s initial setup, then the connection from Roundcube to your email server is already secured. However, the connection from your browser to Roundcube is not, and your emails themselves are sent in the clear. Your Roundcube account itself is also protected only by a password.
In this tutorial, you’ll secure these these three parts of the email pipeline by:
To follow this tutorial, you will need:
You can learn more about multi-factor authentication in the introduction to How To Set Up Multi-Factor Authentication for SSH on Ubuntu 16.04. You can learn more about GPG in How To Use GPG to Encrypt and Sign Messages.
Right now, if you visit your Roundcube installation by using your server’s domain name in your browser, you’ll be connected via HTTP instead of HTTPS. To fully secure the whole communication chain from your browser to your email server, this connection to Roundcube should use SSL/TLS.
One easy way to do this is by using free SSL certificates from Let’s Encrypt. Roundcube is set up on top of the LAMP stack, so you can follow How To Secure Apache with Let’s Encrypt on Ubuntu 16.04 for a detailed walkthrough on setting this up. Here’s a brief summary:
First, install the Let’s Encrypt Client.
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-apache
Then get your SSL certificate and verify that auto-renewal works. Replace example.com
with your domain, and use additional -d
flags for any subdomains or aliases.
- sudo certbot --apache -d example.com
- sudo certbot renew --dry-run
During the interactive configuration (after entering sudo certbot --apache -d example.com
), when asked if you want a basic or secure setup, make sure to choose secure. This will make sure all HTTP traffic is redirected to HTTPS.
You now have a secure connection from your computer to your Roundcube install, which in turns makes a secure connection out to your IMAP/SMTP email server. There are still a few more things you can do to improve the security of your email communications, but they require plugins.
The next step uses plugin to harden the security of a Roundcube account by adding two-factor authentication.
While the Roundcube project is working on GUI functionality for plugins, at the moment, all plugins must be installed via the command line. There are two ways to do this:
.zip
file or in a Git repository), then enabling it by modifying the Roundcube configuration file /var/www/roundcube/config/config.inc.ph
.Some plugins recommend one installation method over the other. The 2FA plugin works with both methods and doesn’t make a recommendation, so here, we’ll use semi-automatic installation because of its ease of use.
Composer is controlled by a composer.json
file stored in $RC_HOME/composer.json
. To enable Composer by creating that configuration file. Roundcube comes with a basic configuration file called composer.json-dist
, so we’ll start from a copy of that.
- cd /var/www/roundcube
- sudo cp composer.json-dist composer.json
There are a few core plugins already specified in this default file, so next, run Composer to install these and finish its initial configuration. Make sure you run Composer from the /var/www/roundcube
directory.
- sudo composer install
Next, to add the 2FA plugin, we need to add it to the composer.json
file.
The syntax of a plugin line is "organization/plugin_name": "version_or_branch"
. So for the 2FA plugin, the line you’ll add is "alexandregz/twofactor_gauthenticator": "dev-master"
.
Open the composer.json
file for editing using nano
or your favorite text editor.
- sudo nano /var/www/roundcube/composer.json
Look for the require block, which begins with "require": {
. Each line between the curly brackets ({
and }
) is a plugin line. All of the plugin lines in the block should end with a comma except for the very last entry.
Add the 2FA plugin line to the end of the block, and make sure to add a comma to the preceding line.
. . .
"require": {
"php": ">=5.4.0",
"pear/pear-core-minimal": "~1.10.1",
"pear/net_socket": "~1.2.1",
"pear/auth_sasl": "~1.1.0",
"pear/net_idna2": "~0.2.0",
"pear/mail_mime": "~1.10.0",
"pear/net_smtp": "~1.7.1",
"pear/crypt_gpg": "~1.6.2",
"pear/net_sieve": "~1.4.0",
"roundcube/plugin-installer": "~0.1.6",
"endroid/qr-code": "~1.6.5",
"alexandregz/twofactor_gauthenticator": "dev-master"
},
. . .
Save and close the file, then run tell Composer to update its package information to install the new plugin.
- sudo composer update
When Composer asks if you want to enable the plugin, enter Y
to continue. Once it’s intalled, log out of Roundcube and log back in to enable the plugin.
Now that the plugin is installed, we need use to to set it up 2FA on our account via Roundcube’s GUI.
To get started, log in to Roundcube using your server IP or domain in your browser. Click on the Settings button in the right hand corner, then 2-Factor Authentication in the left side navigation.
In the 2-Factor Authentication options section, click on the Activate checkbox, then click Create secret.
Next, click Show recovery codes and store the four displayed recovery codes in a safe place. You’ll use these codes to log in if you can’t generate a token (for example, if you lose your phone).
Finally, click the Save button.
This enables 2FA, but now you need to add the secret to your TOTP-compatible app, like Google Authenticator. Click the Show QR code button that appeared after you saved your secret and scan the code with your app. If the scan doesn’t work, you can also enter the secret manually.
Finally, once your app is generating codes, make sure that it works by entering a code into the field next to the Check code button, then click that button. If it works, you’ll see a window that reads Code OK, and you can click the OK button at the bottom to close that window. If there’s a problem, try re-adding the secret to your app.
The final step of securing your digital communications is encrypting the actual messages you send via email. We’ll do this in the next step using plugin called Enigma.
The Enigma plugin adds support for viewing and sending signed, encrypted emails. If you followed the previous Roundcube installation tutorial, then the Enigma plugin is already enabled on your installation. If not, you can follow the same procedure you used for the 2FA plugin in Step 2 to add the Enigma plugin now.
To start, we need to enable some default encryption options. Log in to Roundcube and click on the Settings button in the upper right hand corner. From there, click on Preferences and then Encryption under the Section list.
There are 7 encryption settings in the Main Options list. Enabling all 7 will give the most security, but that comes with some trade-off in usability.
Here are each of the options in the Main Options menu and our suggestions (necessary, recommended, or optional) for each, but you should choose the settings that fit your use case:
Once you’ve chosen your settings, click Save. Next, click on Identities in the Settings column.
The default setting is a single identity with the email address you signed up with. Click on the email and fill in the Display Name field. You can optionally fill out the other fields, like Organization. When you’re done, click the Save button.
The last part of the configuration is creating a key. Click PGP Keys in the left navigation.
If you have a GPG key already, you can click Import in the top right and import your secret key, then click it again to import your public key.
If you don’t have a GPG key, or if you want to create a new one, click the plus (+) button at the bottom of the PGP Keys column. From there, choose the identity you want to create the key for and select the key strength (the bigger the key size, the harder it is to break the encryption, but the slower it is to perform the encryption). Finally, choose a strong password and click Save.
Warning: There is a bug that prevents the creation of new keys in Roundcube when using Chrome. If you normally use Chrome, switch temporarily to another browser to create a new key. Once there is a key in Chrome, importing key pairs and signing/encrypting work as expected.
When you receive a verified signed email, Roundcube displays a green Verified signature from notification at the top:
When you receive and decrypt an encrypted email, Roundcube displays a Message decrypted notification:
To use GPG encryption in your messages, compose a new email by clicking the Mail icon in the upper left, then Compose. Click the Encryption icon to see the encryption options available to you. These depend on what you chose in the encryption settings. If you followed our recommendations, you should see Digitally sign this message, Encrypt this message, and Attach my public key. When you send an email, check the encryption options you want.
By adding SSL, two-factor authentication, and GPG encryption, your email pipeline is significantly more secure. From here, you can continue expanding and customizing Roundcube by exploring the Roundcube Plugin Repository.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
It would be nice to enhance this article by describing how is it possible to use POP, IMAP & SMTP after 2FA enabled.
What a great one)