Understand Linux configuration files
Introduction
Each Linux Program is an executable file that contains a list of operation codes. The CPU will execute these operation codes to complete specific operations. For example, the LS command is provided by the/bin/ls file. This file contains a list of machine commands, which must be used to display the list of files in the current directory on the screen. Almost every program's behavior can be customized by modifying its configuration file according to your preferences or needs.
Is there a standard configuration file format in Linux?
In a word, no. Users who are not familiar with Linux will be frustrated, because every configuration file looks like a new challenge. In Linux, Every programmer is free to choose his or her preferred configuration file format. You can select many formats, including the/etc/shells file (which contains a list of shells separated by a line break), to the complicated/etc/httpd. conf file of Apache.
What is a system configuration file?
The kernel itself can also be seen as a "program ". Why does the kernel need a configuration file? The kernel needs to know the list of users and groups in the system, and then manage the file permissions (that is, determine whether a specific user (unix_users) can open a file based on the permissions ). Note that these files are not explicitly read by the program, but are read by a function provided by the system library and used by the kernel. For example, when a program requires a user's (encrypted) password, the/etc/passwd file should not be opened. Instead, the program should call the getpw () function of the system library. This type of function is also called by the system. To open the/etc/passwd file and then find the password of the requested user is determined by the kernel (through the system library.
Unless otherwise specified, most configuration files in Red Hat Linux are in the/etc directory. Configuration files can be roughly divided into the following categories:
Access Files
/Etc/host. conf tells the network Domain Name Server how to find the host name. (Usually/etc/hosts, and then the name server; you can change it through netconf)/etc/hosts contains a list of known hosts (in the local network. If the system IP address is not dynamically generated, you can use it. For simple host name resolution (Dot-based representation), before requesting a DNS or NIS network name server,/etc/hosts. conf usually tells the DNS program to check the domain name first. For details about/etc/hosts. Allow, refer to the online help page of hosts_access. Read by tcpd at least. For details about/etc/hosts. Deny, refer to the online help page of hosts_access. Read by tcpd at least.
Guide and login/logout
/Etc/issue &/etc/issue.net these files are read by mingetty (and similar programs) and used to access the slave terminal (Issue) or via Telnet session (issue.net) the connected user displays a "welcome" string. These include several lines of information that declares the Red Hat version number, name, and kernel ID. They are used by RC. Local.
/Etc/RedHat-release contains a line of information about the Red Hat version number and name. Used by RC. Local.
/Etc/rc. d/RC is usually run at all running levels and transmitted as parameters. For example, to guide the machine in graph mode (X-server), run the following command on the command line: init 5. Running Level 5 indicates guiding the system in graphic mode.
/Etc/rc. d/rc. Local is informal. It can be called from RC, RC. sysinit, or/etc/inittab.
/Etc/rc. d/rc. sysinit is usually the first script of all running levels.
/Etc/rc. d/RC/rcX. d scripts run from RC (X indicates any number between 1 and 5 ). These directories are specific "Run-level" directories. When the system starts, it identifies the running level to be started, and then calls all the startup scripts in a specific directory of the running level. For example, the system usually displays the "entering run-Level 3" message after the boot message, which means/etc/rc. all the initialization scripts in the D/rc3.d/directory will be called.
File System
The kernel provides an interface to display some of its data structures. These data structures may be useful for determining system parameters such as use interruptions, initialized devices, and memory statistics. This interface is provided as an independent but virtual file system, called/proc file system. Many system utilities use the values in the file system to display system statistics. For example, the/proc/modules file lists the modules currently loaded in the system. The lsmod command reads this information and displays it in a format that people can understand. The mtab file specified in the following table reads the/proc/mount file containing the currently installed file system in the same way.
/Etc/mtab will change with the change of the/proc/mount file. In other words, when the file system is installed and uninstalled, the changes will be immediately reflected in this file.
/Etc/fstab lists the file systems that can be installed on the computer. This is important because the computer will run the Mount-a command during boot, which is responsible for installing each file system with the "1" mark in the penultimate column of fstab.
Configuration of all operations (create directory, copy, format, and so on) on the/etc/mtools. conf DOS file system.
System Management
/Etc/group contains a valid group name and users in the specified group. A single user can execute multiple tasks in multiple groups. For example, if a "user" is a member of the "Project 1" project group and an administrator, the entry in the group file looks like this: User :*: group-ID: project1/etc/nologin if a/etc/nologin file exists, login (1) will only allow access by the root user.
It will display the content of this file to other users and refuse to log on to it.
For etc/passwd, see "Man passwd ". It contains some user account information, including the password (if not encrypted by the shadow program ).
/Etc/rpmrc RPM command configuration. All RPM command line options can be set in this file, so that when any RPM command runs in this system, all options will apply globally.
/Etc/securetty contains the device name, which is composed of tty lines (each line has a name, excluding the previous/dev/). The root user is allowed to log on here.
/Etc/usertty/etc/shadow contains the encrypted user account password and password validity information. The following fields are included:
Login Name
Encrypted password
Number of days from January 1, January 1, 1970 to the last Password Change
Days before the password can be changed
Days before the password must be changed
Number of days the user is warned before the password expires
Number of days after Password Expiration when the account is disabled
Number of days from January 1, January 1, 1970 to Account Disabled
/Etc/shells contains a list of possible "shells" available to the system.
/Etc/motd daily message, which is used when the administrator wants to send a message to all users on the Linux server.
Networking
/Etc/gated. conf gated configuration. It can only be used by the gated daemon.
/Etc/gated. version contains the version number of the gated daemon.
/Etc/gateway is optional by the routed daemon.
/Etc/networks lists the network names and network addresses that can be accessed from the network connected by the machine. Use the routing command. The network name is allowed.
/Etc/protocols lists the currently available protocols. See the nag (Network Administrator guide, network administrators Guide) and online help page.
The C interface is getprotoent. It cannot be changed.
/Etc/resolv. conf tells the kernel which name server to query when the program requests to "parse" an IP address.
/Etc/RPC contains RPC commands/rules, which can be used in NFS calls or remote file system installation.
/Etc/exports file system (NFS) to be exported and its permissions.
/Etc/services converts the network service name to the port number/protocol. It is read by inetd, telnet, tcpdump, and some other programs. There are some C access routines.
/Etc/inetd. conf inetd configuration file. See the inetd online help page. Contains entries for each network service. inetd must control the daemon or other services for these network services. Note that services will run, but are commented out in/etc/services, so that these services will become unavailable even when they are running. Format: <SERVICE_NAME> <sock_type> <proto> <flags> <user> <server_path> <ARGs>
The configuration file of/etc/sendmail. cf mail program Sendmail. It is relatively obscure and hard to understand.
/Etc/sysconfig/network indicates networking = yes or no. Read by RC. sysinit at least.
/Etc/sysconfig/network-scripts/if * Red Hat Network configuration script.
System commands
System commands must control the system exclusively and make everything work normally. All programs such as login (completing the console user authentication phase) or bash (providing interaction between users and computers) are system commands. Therefore, files related to them are particularly important. This category contains the following files that interest users and administrators.
/Etc/Lilo. conf contains the system's default pilot command line parameters, as well as different images used at startup. You can press the tab key when prompted by lilo boot to see this list.
/Etc/logrotate. conf maintain the log files in the/var/log directory.
/Etc/identd. conf identd is a server that implements the standard ident user identification protocol proposed by TCP/IP according to the method specified in RFC 1413. The operating principle of identd is to find a specific TCP/IP connection and return the User Name of the process that owns the connection. It can also return other information, not the user name. See the identd online help page.
/Etc/lD. So. conf "Dynamic Link program" (dynamic linker) configuration.
/Etc/inittab is the first configuration file in UNIX. The first program started after a unix machine is opened is INIT, which knows what to start. This is because of the existence of inittab. When the running level changes, init reads the inittab and controls the startup of the main process.
/Etc/termcap a database that contains all possible terminal types and the performance of these terminals.
Daemon
A daemon is a program running in non-interactive mode. In general, daemon tasks are related to the network areas: they wait for a connection to provide services through the connection. Linux can use many daemon processes from the Web server to the FTP server.
The configuration file of the/etc/syslogd. conf syslogd daemon. Syslogd is a daemon that records messages (written to a disk) sent from other programs to the system. This service is often used by some daemon. These daemon do not have other methods to send signals that may cause problems or send messages to users.
The configuration file of Apache on the/etc/httpd. conf web server. This file is generally not in/etc. It may be in/usr/local/httpd/CONF/or/etc/httpd/CONF/, but to determine its location, you also need to check the specific Apache installation information.
/Etc/CONF. modules or/etc/modules. conf kerneld configuration file. Interestingly, kerneld is not the "as a daemon" kernel. It is actually a daemon process responsible for loading additional kernel modules quickly as needed.
User Program
There are countless "user" programs in Linux (and general UNIX. The most common user program configuration file is/etc/lynx. cfg. This is the configuration file of the famous text browser lynx. Through this file, you can define the proxy server, the character set to be used, and so on. The following code sample shows a part of the lynx. cfg file. modifying this code can change the proxy server settings of the Linux system. By default, these settings apply to all users running lynx in their respective shells, unless a user resets the default configuration file by specifying -- CFG = "mylynx. cfg.
Proxy Server settings in/etc/lynx. cfg
. H1 proxy
. H2 http_proxy
. H2 https_proxy
. H2 ftp_proxy
. H2 gopher_proxy
. H2 news_proxy
. H2 nntp_proxy
# Lynx version 2.2 and beyond supports the use of proxy servers that can act
# Firewall gateways and caching servers. They are preferable to the older
# Gateway servers. Each protocol used by Lynx can be mapped separately using
# Protocol_proxy environment variables (see Lynx users guide). If you have
# Not set them externally, you can set them at run time via this configuration f
Ile.
# They will not override external settings. The no_proxy variable can be used
# To inhibit proxying to selected regions of the Web (see below). Note that on
# VMS these proxy variables are set as process logicals rather than symbols,
# Preserve lowercasing, And will outlive the lynx image.
#
. Ex 15
Http_proxy: http://proxy3.in.ibm.com: 80/
Ftp_proxy: http://proxy3.in.ibm.com: 80/
# Http_proxy: http://penguin.in.ibm.com: 8080
# Ftp_proxy: http://penguin.in.ibm.com: 8080/
. H2 no_proxy
# The no_proxy variable can be a comma-separated list of strings defining
# No-proxy zones in the DNS domain name space. If a tail substring of
# Domain-path for a host matches one of these strings, transactions with that
# Node will not be proxied.
. Ex
No_proxy: demiurge.in.ibm.com, Demiurge
Change configuration file
When changing the configuration file, if the program is not controlled by the system administrator or the kernel, make sure that the program that uses the configuration is restarted. Normal users do not have the permission to start or stop system programs and/or daemon processes.
Kernel
Changing the configuration file in the kernel immediately affects the system. For example, changing the passwd file to add a user will immediately make the user available. In addition, the/proc/sys directory of any Linux system has some kernel adjustable parameters. Only Super Users can get write access to all these files; other users only have read-only access. The classification of files in this directory is the same as that of Linux kernel source code. Each file in this directory represents a kernel data structure that can be dynamically modified to change the system performance.
Note: before changing any file value, make sure that you fully understand the file to avoid irreparable damage to the system.
Files in the/proc/sys/kernel/directory
File Name Description
Maximum number of tasks that the threads-Max kernel can run.
CTRL-alt-del if the value is 1, press these keys in sequence to completely reboot the system.
If the value of sysrq is 1, alt-sysrq is activated.
Osrelease: displays the release version number of the operating system.
Ostype displays the operating system type.
The Host Name of the hostname system.
The domainname network domain. The system is part of the network domain.
Modprobe specifies whether modprobe should automatically run at startup and load required modules.
Daemon and system programs
A daemon is a program that always runs in the background. It silently executes its own tasks. Common daemon include in. ftpd (FTP server daemon), In. telnetd (telnet server daemon), and syslogd (System Logging Daemon ). Some daemon will closely monitor the configuration file during running and automatically reload it when the configuration file changes. However, most daemon do not automatically reload the configuration file. We need to "tell" in some way that these daemon configuration files have been changed and should be reloaded. You can use service commands to restart the service (on Red Hat Linux ).
For example, if we change the network configuration, we need to issue the following:
Service Network restart.
Note: The most common examples of these services are the scripts in the/etc/rc. d/init. d/* Directory, which are started by init when the system is booted. Therefore, you can restart the service by performing the following operations:
/Etc/rc. d/init. d/<script-for-the-service> Start | stop | status
Start, stop, and status are input values accepted by these scripts for operations.
User Program
The user or system program reads the configuration file every time it is started. Even so, remember that some system programs are different when the computer is turned on. Their behavior depends on what is read in the configuration file in/etc. Therefore, when your program starts for the first time, it reads the default configuration from the files in the/etc/directory. You can then customize the program by using the RC and. (DOT) files, as shown in the following section.
User Configuration File:. (point) file and RC file
We have seen how to easily configure the program. But what if some people do not like to configure the program in/etc? "Normal" users cannot simply enter/etc and change the configuration file. From the perspective of the file system, the configuration file owner is a root user! This is why most user programs define two configuration files: the first is at the "System" level, located at/etc/, and the other is "dedicated" for users ", it can be found in his or her main directory.
For example, I installed a very useful wget utility in my system. /Etc/has a/etc/wgetrc file. In my main directory, there is a directory named. wgetrc file, which describes the custom configuration (this configuration file is loaded only when I, that is, the user runs the wget command ). Other users can also have the. wgetrc file in their home directory (/home/Other). Of course, only these users can read the file when running the wget command. In other words, the/etc/wgetrc file provides the "default" value for wget. The/home/XXX/. wgetrc file lists the "custom items" of a user ". The important thing is that this is only a "general rule", not all cases. For example, a program like pine does not have any files in/etc/. It only has a custom configuration file named. pinerc in the user's home directory. Other programs may only have default configuration files in/etc/, and users may not be allowed to "customize" These configuration files (this is the case where only a few config. files are in the/etc directory ).
Normally used RC and. (point) files
File Name Description
~ /. For bash_login, see "Man Bash ". If ~ /. Bash_profile does not exist, Bash will ~ /. Bash_login ~ /. Bash_profile processing.
~ /. For bash_logout, see "Man Bash ". It is referenced by the bash logon shell when exiting.
~ /. Bash_profile is referenced by bash logon shell after/etc/profile.
~ /. Bash_history list of commands previously executed.
~ /. For bashrc, see "Man Bash ". Referenced by bash non-Logon Interactive Shell (no other files ). Unless bash_env or env is set, non-interactive shell does not reference any files.
~ /. Emacs is read by EMAC at startup.
~ /. Forward
If an email address is included, all emails sent ~ The owner's email will be forwarded to this email address.
~ /. Fvwmrc ~ /. Configuration files of fvwm2rc FVWM and fvwm2 (basic X Window Manager.
~ /. For details about hushlogin, refer to "Man login ". Cause "No prompt" login (no email notification, Last login information, or mod information ).
~ The user initialization file of the/. Mail. RC email program.
~ /. Ncftp/ncftp program directory; contains bookmarks, logs, macros, preferences, and tracking information. See man ncftp. Ncftp aims to provide a powerful and flexible interface for the Internet standard file transfer protocol. It is designed to replace the standard FTP program used by the system.
~ /. For the profile, see "Man Bash ". If ~ /. Bash_profile and ~ /. Bash_login file does not exist, Bash will ~ /. Profile ~ /. Bash_profile is processed and used by other shell that inherit the bourn.
~ /. Pinerc pine Configuration
~ /. Muttrc mutt Configuration
~ The/. exrc file can control the VI configuration.
Example: Set ai sm ruler
Writing the above line in this file will enable VI to set Automatic indent, matching brackets, displaying row numbers and row-column options.
~ /. Vimrc default "Vim" configuration file. Same as. exrc.
~ /. Gtkrc gnome Toolkit (gnome Toolkit ).
~ /. Kderc KDE configuration.
~ /. Netrc Default FTP login name and password.
~ /. Rhosts is used by r-tools (such as RSH and rlogin. Because it is easy to impersonate a host
Low.
Required by the user (~ /Owner) or a Super User.
Lists hosts from which users can access this account.
If it is a symbolic link, it is ignored.
~ /. For details about rpmrc, refer to "Man RPM ". If/etc/rpmrc does not exist, it is read by rpm.
~ The/. Signature message text will be automatically appended to the end of the email sent from this account.
~ /. Twmrc TWM (The Window Manager) configuration file.
~ /. Xinitrc is read by X at startup (instead of by xinit script ). Generally, some programs are started.
Example: exec/usr/sbin/startkde
If this line of content exists in this file, Kde window manager is started when the startx command is issued from this account ).
~ /. Xmodmaprc this file is transferred to the xmodmap program and can be named as any file (for example ~ /. Xmodmap and ~ /. Keymap. km ).
~ /. Xserverrc if xinit can find the X to be executed, xinit will run the file as the X server.
~ The default email history file of/news/sent-message-IDs gnus.
~ /. Xauthority is read and written by the xdm program to process permissions. See the X, xdm, and Xauth online help pages.
~ /. Xdefaults,
~ /. Xdefaults-hostname is read by X application during host hostname startup. If the-hostname file cannot be found, find the. xdefaults file.
~ /. Xmodmap points to. xmodmaprc; Red Hat has a. xinitrc file with this name.
~ /. Xresources is usually the name of the file that is sent to xrdb to load x resource database. It is designed to prevent applications from reading a long. xdefaults file. (I used it in some cases ~ /. Xres .)
~ /Mbox
The user's old email.