1. Overview

The ability to tweak Linux exactly as we need makes it powerful to use. While most distributions offer sophisticated interfaces for configuring the system, these UIs just modify plaintext config files spread across the system. So, understanding these config files will remove our dependence on these UIs and make us more proficient with Linux.

In this tutorial, we’ll see where these files are located and what they do. Thanks to the Filesystem Hierarchy Standard, the directories and files discussed in this tutorial should be consistent across distributions.

2. Global Config Files

The global configuration files define the behavior for the entire system.

These files are usually located in the root (/) partition and require superuser access.

2.1. /etc/

Most global config files are located in the /etc directory.

The /etc/ directory feels more like a filesystem and has many sub-directories, each having related config files.

The following is a list of the most useful of these sub-directories:

  • /etc/X11/xorg specific config files
  • /etc/cups/ – sub-directory containing configuration for the Common UNIX Printing System
  • /etc/xdg/ – global configs for applications following freedesktop.org specification
  • /etc/ssh/ – used to configure OpenSSH server behavior for the whole system
  • /etc/apparmor.d/ – contains config files for the AppArmor system
  • /etc/udev/udev related configuration

2.2. /etc/opt/

The /etc/opt/ directory is supposed to contain global configuration for applications installed inside /opt/. But, Linux does not enforce this. As a result, we can often see /opt/ directory full of user-installed software while /etc/opt/ remains empty.

2.3. /etc/default/

The config files under /etc/default/ historically contained settings for services/daemons for use with initialization systems such as upstart. But, with the advent of systemd, this directory now mainly contains settings for userland applications.

The system does not overwrite files inside /etc/default/. This means that once we define application behavior here, they will stay consistent through system upgrades.

2.4. Important Global Config Files

Some of the most useful global config files are:

  • /etc/resolv.conf – used to define the DNS server(s) to use
  • /etc/bash.bashrc – used to define the commands to execute when a user launches the bash shell
  • /etc/profile – the login shell executes the commands in .profile script during startup
  • /etc/dhcp/dhclient.conf – stores network related info required by DHCP clients
  • /etc/fstab – decides where to mount all the partitions available to the system
  • /etc/hostname – set the hostname for the machine
  • /etc/hosts – a file which maps IP addresses to their hostnames
  • /etc/hosts.deny – the remote hosts listed here are denied access to the machine
  • /etc/mime.types – lists MIME-TYPES and filename extensions associated with them
  • /etc/motd – configure the text shown when a user logs in to the host
  • /etc/timezone – set the local timezone
  • /etc/sudoers – the sudoers file controls the sudo related permission for users
  • /etc/httpd/conf and /etc/httpd.conf.d – configuration for the apache web server
  • /etc/default/grub – contains configuration used by the update-grub for generating /boot/grub/grub.cfg
  • /boot/grub/grub.cfg – the update-grub command auto-generates this file using the settings defined in /etc/default/grub

3. User-Specific Configuration

User-specific config files modify system behavior only for the user who has defined it.

These files usually reside inside a user’s home directory and don’t require superuser permissions for modification.

One thing to note is that user-specific configs always have higher precedence than global configs. Thus, an application will always prefer a user-specific config as long as it exists.

When it comes to user-specific configurations, we have applications following two standards.

3.1. Traditional Configs

Traditionally, if an application had a single config file, it would be stored at /home/<username>/.<app_name{rc}>. But, if there were more than a single file, the configs would be stored inside the directory /home/<username>/.<app_name>.

A prime example of this behavior is the vim editor.

3.2. Config Files Following the XDG Standard

freedesktop.org decided the old system was messy and developed the XDG base directory specification.

As per the XDG standard, all user-specific config files are stored inside the $XDG_CONFIG_HOME directory (usually /home/<username>/.config).

Inside $XDG_CONFIG_HOME, each application creates its own sub-directories to store configs.

The NeoVim editor and many actively developed applications now follow the XDG base directory specification. This is also very convenient for users as backing up the single $XDG_CONFIG_HOME directory saves all configs.

3.3. Important User-Specific Config Files

Some of the most commonly used user-specific config files are:

  • $HOME/.xinitrc – this allows us to set the directives for starting a window manager when using the startx command
  • $HOME/.vimrc – vim configuration
  • $HOME/.bashrc – script executed by bash when the user starts a non-login shell
  • $XDG_CONFIG_HOME/nvim/init.vim – neovim configuration
  • $HOME/.editor – sets the default editor for the user
  • $HOME/.gitconfig – sets the default name and e-mail address to use for git commits
  • $HOME/.profile – the login shell executes the commands in the .profile script during startup
  • $HOME/.ssh/configssh configuration for a specific user

4. Conclusion

In this article, we learned the two types of config files available in Linux and where we can find them.

Also, we went through commonly used directories for storing configurations and how older and newer applications handle user-specific configs.

Since Linux does not enforce a specific format for these config files, their syntax can vary wildly. But, if we are willing to spend a bit of time and effort, config files can free us from the limitations of UIs targeted at novice users.

Comments are closed on this article!