/etc
system-wide configuration/etc is where the system’s settings live. Users, host names, DNS servers, services — each is a plain text file you can read and edit. There is no registry and no hidden database: to change how a machine behaves, you change a file here.
To know how a machine is set up, read /etc.
Why it exists
Every directory at the top of the tree is there for a reason. This is the problem /etc solves.
Because configuration is not mixed in with the software, a program can be upgraded or reinstalled without losing how it was set up.
A plain file can be searched with grep, compared with diff, copied to another machine and kept in version control. That is what makes Linux servers easy to automate.
Two servers with the same packages differ only in /etc and their data. Back up /etc, and you have the machine’s identity.
What you find inside
Not everything, but the entries worth recognising. Each is marked as a directory, a file, a link or a device.
- passwdfileThe list of user accounts. Despite the name, no passwords.
- shadowfileThe password hashes. Readable only by root.
- hostsfileNames mapped to addresses, checked before the DNS.
- resolv.conffileWhich DNS servers the host asks.
- fstabfileWhich filesystems are mounted at boot, and where.
- sshdirectoryThe SSH server’s and client’s settings, and the host keys.
- systemddirectoryService definitions added or overridden by the administrator.
At the terminal
Four commands that show what this directory is doing on a real machine.
cat /etc/os-releaseShow which distribution and version this machine runs.
cat /etc/hostsShow the names this host resolves without asking the DNS.
grep -r "Port" /etc/ssh/Search every file in a configuration directory for a setting.
sudo cp /etc/fstab /etc/fstab.bakKeep a copy of a file before editing it.
Handle with care
What goes wrong here, and what someone securing or attacking the machine looks at.
A typing mistake in fstab or sudoers can leave a machine unable to boot or you unable to become root. Keep a copy, and use visudo for the sudoers file.
passwd lists the accounts, shadow holds the hashes, and configuration files often contain passwords. Check that secrets are readable only by those who need them.
Editing a service’s file does not change the running service. Reload or restart it with systemctl for the new setting to take effect.