Keeping your Ubuntu config files secure

NOTE: This guide has been written for Ubuntu Focal Fossa 20.04LTS and has also been tested on Trusty Tahr 14.04LTS, Precise Pangolin 12.04 & Lucid Lynx 10.04 although it may work equally well on earlier versions of Ubuntu too.

Overview

As you work through configuring your server and installing various pieces of software you’ll probably not realise just how many configuration files, scripts and the like you need to create or edit to get the system working to your personal tastes. Generally these configuration files need to be stored in folders which are inside the Operating System itself. This means that if for any reason you need to reinstall the Operating System from scratch you will need to re-edit or recreate all these files again.

To save the pain of having to do this I have created a separate folder on one of my “data” drives (which is not part of the OS partition but is instead part of my SnapRAID Array) where I keep all of these configuration files and scripts. I then “point” to the each of them as required. This is simple in Ubuntu through the use of symbolic links. To save even more time should I need to reinstall the Operating System I have created a script to re-create these links for me. The only thing I have to remember is to add to this script as and when I install a new piece of software which needs a configuration file.

How to create a symbolic link on Ubuntu

On a unix-based system the syntax to create a symbolic link (aka a symlink) is as follows:

ln -s name_and_location_of_original_folder_or_file name_and_location_of_required_folder_or_filename

So, using Deluge as an example I would issue the following command:

sudo touch /media/WD40EFRX/RAIDMain/MyScripts/deluged.conf

This command creates a blank file in the MyScripts folder.

Now we want to link this file to the required location so Deluge can find it:

sudo ln -s /media/WD40EFRX/RAIDMain/MyScripts/deluged.conf /etc/init/deluged.conf

obviously substituting /media/WD40EFRX/RAIDMain/MyScripts/ with the location of your scripts folder.

So now the deluged.conf is in the place which Deluge expects it to be AND it is stored away from the Operating system itself so will still exist should I ever wipe Ubuntu and start again from scratch.

You can now edit this config file as required. It doesn’t matter whether you edit the file stored in the /etc/init folder or the one in the MyScripts folder since it’s actually the exact same file, it’s just accessible from two different locations.

In my symbolic link script I would just add this line and I’d execute this script once I’d reinstalled Ubuntu and Deluge:

sudo ln -s /media/WD40EFRX/RAIDMain/MyScripts/deluged.conf /etc/init/deluged.conf