Set the OpenDKIM SYSCONFDIR at compile time by passing --sysconfdir=/etc/opendkim to the ./configure script before building. This ensures configuration files land in the standard directory, avoiding runtime errors and simplifying service management for email signing and verification tasks.
Understanding SYSCONFDIR in OpenDKIM
The SYSCONFDIR variable is a standard autoconf parameter that tells the build system where to install configuration files during the compilation process. For OpenDKIM, this typically includes files like opendkim.conf, key tables, and signing table definitions. If you do not specify this path, the software may default to a non-standard location such as /usr/local/etc, which can cause confusion when trying to start the service or when following documentation that assumes the files are in /etc/opendkim.
By explicitly defining this directory during the configure stage, you align the installation with the expectations of most Linux distributions and systemd service units. This is particularly important if you plan to use the default init scripts or if you rely on specific file permissions that are set up by package managers or community guides.
Why Default Paths Can Be Problematic
When compiling from source without explicit flags, many projects default to /usr/local/etc. However, the OpenDKIM daemon often looks for its primary configuration file in /etc/opendkim/opendkim.conf by default unless told otherwise via command-line arguments or environment variables. Mismatches between where the files are installed and where the daemon expects them result in immediate startup failures. Setting SYSCONFDIR manually prevents this common pitfall.
Prerequisites for Compilation
Before configuring OpenDKIM, ensure your system has all necessary development libraries installed. OpenDKIM depends on several external libraries for cryptographic operations and database connectivity. You will need:
- libmilter: The Sendmail Mail Filter library, which allows OpenDKIM to integrate with mail transfer agents like Postfix or Sendmail.
- libdb: Berkeley DB, used for storing key tables and other lookup data.
- libssl: OpenSSL libraries for handling digital signatures and encryption.
- gcc and make: Standard build tools required to compile C source code.
On Ubuntu or Debian systems, you can install these dependencies using apt-get install libmilter-dev libdb-dev libssl-dev gcc make. On RHEL or CentOS, use yum or dnf to install the corresponding -devel packages. Missing any of these will cause the configure step to fail, halting the entire installation process.
Configuring the Build Environment
Once dependencies are verified, extract the OpenDKIM source tarball and navigate into the directory. The core of the customization happens in the ./configure command. To set the configuration directory, append the --sysconfdir flag followed by your desired path. For most systems, this is /etc/opendkim.
./configure --sysconfdir=/etc/opendkim
This command instructs the build system to place all configuration-related files into /etc/opendkim instead of the default prefix’s etc folder. You can verify that the setting was accepted by checking the output of the configure script, which should list sysconfdir: /etc/opendkim among the final summary lines. If you encounter errors here, they usually relate to missing headers from the prerequisites listed above.
Additional Configuration Flags
While --sysconfdir handles configuration paths, you might also want to specify the binary directory or the PID file location. Common additional flags include:
--prefix=/usr: Installs binaries and libraries in standard system paths rather than/usr/local.--with-milter=/path/to/libmilter: Explicitly points to the libmilter installation if it is not in the default search path.
Combining these ensures a clean integration with your existing mail infrastructure. For example, a full configure command might look like: ./configure --prefix=/usr --sysconfdir=/etc/opendkim --with-milter=/usr/lib/x86_64-linux-gnu.
Compiling and Installing
After a successful configuration, proceed with the standard build sequence. Run make to compile the source code. This step processes the C files and links them against the required libraries. Once make completes without errors, run sudo make install to copy the binaries, libraries, and configuration files to their designated locations.
Because you specified --sysconfdir=/etc/opendkim, you should now find opendkim.conf inside that directory. Verify this by running ls -l /etc/opendkim/. If the files are present, the installation is structurally correct. You can then proceed to populate the configuration file with your domain keys and selector names.
Post-Installation Steps
After installation, create the necessary directories for keys and sockets if they do not exist automatically. Set appropriate ownership and permissions so that the opendkim user can read the private keys but no other user can access them. Typically, this involves creating /etc/opendkim/keys and setting permissions to 750 for the directory and 640 for the key files, owned by root:opendkim.
Finally, enable and start the service. On systemd-based systems, use systemctl enable opendkim and systemctl start opendkim. Check the status with systemctl status opendkim to ensure there are no errors related to missing configuration files or permission denials.
Frequently Asked Questions
What happens if I forget to set SYSCONFDIR?
If you omit this flag, OpenDKIM defaults to /usr/local/etc/opendkim. Your daemon will likely fail to start because it cannot find the expected config file in /etc/opendkim. You would then need to either move the files manually or recompile with the correct path.
Can I change SYSCONFDIR after installation?
No, SYSCONFDIR is baked into the binary during the configure phase. If you need a different path, you must recompile the software from source with the new flag. There is no runtime switch to change the base configuration directory.
Does this affect how OpenDKIM integrates with Postfix?
It does not directly affect the Milter socket path, which is controlled by MilterSocket in the config file. However, ensuring the config file is in the expected location makes it easier to manage and reference from your Postfix main.cf settings.
Is this method compatible with Ubuntu 20.04 LTS?
Yes, compiling from source with custom paths works on Ubuntu 20.04 LTS and newer versions. Ensure you have the correct development packages installed for your specific kernel architecture to avoid linking errors.
How do I verify the configure step worked correctly?
Look at the end of the ./configure output. It prints a summary of all options used. Search for "sysconfdir" in that text block. If it shows your custom path, the build system is ready to generate Makefiles accordingly.