Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand Linux configuration file

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to understand the Linux configuration file, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Introduction to Linux configuration file

Each Linux program is an executable file that contains a list of opcodes that CPU will execute to perform specific operations. For example, the ls command is provided by the / bin/ls file, which contains a list of machine instructions that are needed to display a list of files in the current directory on the screen. The behavior of almost every program can be customized to your preferences or needs by modifying its configuration file.

Is there a standard configuration file format in Linux?

In a word, no. Users who are not familiar with Linux will (certainly) be frustrated because each profile looks like a new challenge to meet. In Linux, every programmer is free to choose his or her preferred configuration file format. There are many formats you can choose from, from the / etc/shells file, which contains a list of shell separated by a newline character, to Apache's complex / etc/httpd.conf file.

What is a system profile?

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 in order to manage file permissions (that is, based on permissions to determine whether a particular user (UNIX_USERS) can open a file). Note that these files are not explicitly read by the program, but by a function provided by the system library and used by the kernel. For example, the / etc/passwd file should not be opened when the program needs a user's (encrypted) password. Instead, the program should call the getpw () function of the system library. This function is also known as a system call. Opening the / etc/passwd file and then finding 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 systems are in the / etc directory. Configuration files can be broadly divided into the following categories:

The access file / etc/host.conf tells the network domain name server how to find the hostname. (usually / etc/hosts, followed by the name server; it can be changed through netconf) / etc/hosts contains a list of known hosts (on the local network). If the IP of the system is not dynamically generated, you can use it. For simple hostname resolution (dot notation), / etc/hosts.conf usually tells the resolver to check here before requesting a DNS or NIS network name server. / etc/hosts.allow Please refer to the online help page of hosts_access. At least read by tcpd. / etc/hosts.deny Please refer to the online help page of hosts_access. At least read by tcpd. Boot and log in / etc/issue & / etc/issue.net these files are read by mingetty (and similar programs) and are used to display a "welcome" string to users connected from the terminal (issue) or through a telnet session (issue.net). They include several lines of information declaring the Red Hat version number, name, and kernel ID. They are used by rc.local. / etc/redhat-release includes a line of information that declares the Red Hat version number and name. Used by rc.local. / etc/rc.d/rc usually runs at all run levels, and the level is passed as a parameter. For example, to boot the machine in Graphics mode (X-Server), run the following command on the command line: init 5. Runlevel 5 indicates booting the system in graphical mode. / etc/rc.d/rc.local is informal. Can be called from rc, rc.sysinit, or / etc/inittab. / etc/rc.d/rc.sysinit is usually the first script of all run levels. / etc/rc.d/rc/rcX.d script run from rc (X represents any number between 1 and 5). These directories are directories for a specific "run level". When the system starts, it identifies the run level to start and then invokes all startup scripts that exist in the specific directory of that run level. For example, when the system boots, it usually displays a "entering run-level 3" message after the boot message; this means that all initialization scripts in the / etc/rc.d/rc3.d/ directory will be called. File system

The kernel provides an interface to display some of its data structures that can be useful for determining system parameters such as interrupts used, initialized devices, and memory statistics. This interface is provided as a separate but virtual file system called the / proc file system. Many system utilities use values that exist in this file system to display system statistics. For example, the / proc/modules file lists the currently loaded modules 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 table below reads the / proc/mount file that contains the currently installed file system in the same way.

/ etc/mtab this will change as the / proc/mount file changes. In other words, when the file system is mounted and unmounted, the changes are immediately reflected in this file. / etc/fstab lists the current "mountable" file systems on your computer. This is important because when the computer boots, it runs the mount-a command, which installs every file system marked "1" in the penultimate column of fstab. Configuration of all operations (creating directories, copying, formatting, and so on) on a file system of type / etc/mtools.confDOS. System Administration / etc/group contains valid group names and users included in the specified group. If a single user performs multiple tasks, he or she can exist in multiple groups. For example, if a "user" is a member of the "project1" project group and is also an administrator, his entry will look like this in the group file: user: *: group-id: project1/etc/nologin if the / etc/nologin file exists, login (1) will only allow root users to access. It will display the contents of this file to other users and deny them login. See "man passwd" for etc/passwd. It contains some user account information, including passwords (if not encrypted by the shadow program). / etc/rpmrcrpm command configuration. All rpm command line options can be set together in this file so that when any rpm command runs on the system, all options apply globally. / etc/securetty contains the device name and consists of tty lines (one name per line, excluding the previous / dev/), where root users are allowed to log in. / etc/usertty

/ etc/shadow contains encrypted user account password information and can also include password aging information. The fields included are:

Login name

Encrypted password

Number of days from January 1, 1970 to the last time the password was changed

Number of days before the password can be changed

Number of days before the password must be changed

The number of days before the password expires that the user is warned

The number of days that the account has been disabled after the password expires

The number of days from January 1, 1970 to the number of days that the account was banned

/ etc/shells contains a list of possible "shell" available to the system. / etc/motd daily message; used when the administrator wants to communicate a message to all users of the Linux server. Configuration of networking / etc/gated.confgated. Can only be used by gated daemons. / etc/gated.version contains the version number of the gated daemon. / etc/gateway is optionally used by the routed daemon. / etc/networks lists the network names and network addresses that can be accessed from the network to which the machine is connected. Used by routing commands. Allow the use of network names. / etc/protocols lists the currently available protocols. Refer to NAG (Network Administrator's Guide, Network Administrators Guide) and the online help page. The C interface is getprotoent. It must not 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 instructions / rules that can be used in NFS calls, remote file system installations, and so on. / etc/exports the file system (NFS) to be exported and the permissions on it. / etc/services converts the network service name to a port number / protocol. It is read by inetd, telnet, tcpdump and some other programs. There are some C access routines. Configuration file for / etc/inetd.confinetd. See the inetd online help page. Contains entries for each network service for which inetd must control daemons or other services. Note that the services will run, but they are commented out in / etc/services so that even if they are running, they will not be available. The format is: / etc/sendmail.cf mail program sendmail configuration file. It's obscure and difficult to understand. / etc/sysconfig/network indicates NETWORKING=yes or no. At least read by rc.sysinit. / etc/sysconfig/network-scripts/if*Red Hat network configuration script. System command

The system commands to monopolize the control system and make everything work properly. All programs such as login (completing the console user authentication phase) or bash (which provides interaction between the user and the computer) are system commands. Therefore, the documents relating to them are also particularly important. The following files are of interest to users and administrators in this category.

/ etc/lilo.conf contains the default boot command line parameters for the system, as well as the different images used at startup. You can see this list by pressing the Tab key at the LILO boot prompt. / etc/logrotate.conf maintains log files in the / var/log directory. / etc/identd.confidentd is a server that implements the standard IDENT user identification protocol proposed by TCP/IP as specified in the RFC 1413 documentation. Identd works by finding a specific TCP/IP connection and returning the user name of the process that owns it. As an option, it can also return other information instead of the user name. See the identd online help page. Configuration of / etc/ld.so.conf dynamic Linker (Dynamic Linker). / etc/inittab this is the first configuration file in UNIX in chronological terms. The first program that starts after a UNIX machine is turned on is init, which knows what to start because of the existence of inittab. When the run level changes, init reads the inittab and then controls the startup of the main process. / etc/termcap A database containing all possible terminal types and the performance of these terminals. Daemon process

A daemon is a program that runs in non-interactive mode. In general, daemon tasks are related to the networking area: they wait for a connection to provide services through the connection. Linux can use many daemons from the Web server to the ftp server.

Configuration file for the / etc/syslogd.confsyslogd daemon. Syslogd is a daemon that records (writes to disk) messages sent to the system from other programs. This service is particularly commonly used by daemons that have no other way to signal a possible problem or send a message to the user. Configuration file for / etc/httpd.confWeb server Apache. This file is usually 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 specific Apache installation information. Configuration file for / etc/conf.modules or / etc/modules.confkerneld. Interestingly, kerneld is not a kernel "as a daemon". It is actually a daemon that is responsible for loading additional kernel modules "quickly" when needed. User program

In Linux (and UNIX in general), there are countless "user" programs. One of the most common user program configuration files is / etc/lynx.cfg. This is the configuration file for the famous text browser lynx. Through this file, you can define the proxy server, the character set to use, and so on. The following code sample shows a portion of the lynx.cfg file that can be modified to change the proxy server settings of the Linux system. By default, these settings apply to all users running lynx in their own shell, unless a user resets the default profile by specifying-- cfg = "mylynx.cfg".

Proxy server settings in / etc/lynx.cfg

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

.h2 proxy

.h3 HTTP_PROXY

.h3 HTTPS_PROXY

.h3 FTP_PROXY

.h3 GOPHER_PROXY

.h3 NEWS_PROXY

.h3 NNTP_PROXY

# Lynx version 2.2 and beyond supports the use of proxy servers that can act as

# 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 file.

# 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, to

# 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/

.h3 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 the

# 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 the configuration file

When changing the configuration file, if the program is not controlled by the system administrator or kernel, be sure to restart the program that uses the configuration. Ordinary users usually do not have permission to start or stop system programs and / or daemons.

Kernel

Changing the configuration file in the kernel immediately affects the system. For example, changing the passwd file to add a user immediately makes that user available. And any Linux system has some kernel tunable parameters in the / proc/sys directory. Only superusers have write access to all of these files; other users only have read-only access. The files in this directory are classified in the same way as the Linux kernel source code. Each file in this directory represents a kernel data structure that can be dynamically modified to change system performance.

Note: before changing any of the values of any of these files, you should make sure that you fully understand the file to avoid irreparable damage to the system.

Files in / proc/sys/kernel/ directory

The file name describes the maximum number of tasks that the threads-max kernel can run. If the value of ctrl-alt-del is 1, pressing these keys sequentially will reboot the system "thoroughly". The sysrq is active if the value is 1 and the value is 1. Osrelease displays the release number of the operating system ostype shows the type of operating system. The hostname of the hostname system. Domainname network domain, of which the system is a part. Modprobe specifies whether modprobe should automatically run and load the necessary modules at startup. Daemons and system programs

A daemon is a program that always runs in the background and performs its tasks silently. Common daemons are in.ftpd (ftp server daemon), in.telnetd (telnet server daemon), and syslogd (system logging daemon). Some daemons closely monitor the configuration file at run time and automatically reload it when the configuration file changes. However, most daemons do not automatically reload the configuration file. We need to somehow "tell" that the daemon configuration files have been changed and should be reloaded. You can do this (on Red Hat Linux systems) by restarting the service using the service command.

For example, if we change the network configuration, we need to issue:

Service network restart .

Note: the most common of these services are scripts that exist in the / etc/rc.d/init.d/* directory, which are started by init when the system is booted. Therefore, you can also restart the service by doing the following:

/ etc/rc.d/init.d/ start | stop | status

Start, stop, and status are the input values accepted by these scripts to perform operations.

User program

The user or system program reads its configuration file each time it starts. Keep in mind, however, that some system programs behave differently when the computer is turned on, and their behavior depends on what they read in the configuration file in / etc/. So when the user program starts for the first time, it reads the default configuration from a file that exists in the / etc/ directory. Users can then customize the program by using rc and. (dot) files, as shown in the following section.

User profile:. (dot) file and rc file

We have seen how easily to configure the program. But what if some people don't like the way programs are configured in / etc/? "normal" users cannot simply enter / etc and change the configuration file; from a file system point of view, the owner of the configuration file is the root user! This is why most user programs define two profiles: the first is at the "system" level, located at / etc/;, and the other is "dedicated" to the user and can be found in his or her home directory.

For example, I installed the very useful wget utility on my system. There is a / etc/wgetrc file in / etc/. In my home directory, there is a file called .wgetrc that describes my customized configuration (this configuration file is loaded only when I, the user, runs the wget command). Other users can also have .wgetrc files in their own home directory (/ home/other); of course, this file is only read by these users when they run the wget command. In other words, the / etc/wgetrc file provides a "default" value for wget, while the / home/xxx/.wgetrc file enumerates a user's "customization". The important thing is that this is only a "general rule", not in all cases. For example, a program like pine does not have any files in / etc/, but only a custom configuration file called .pinerc in the user's home directory. Other programs may only have default configuration files in / etc/, and may not allow users to "customize" these configuration files (there are only a few config in the / etc directory.) This is the case with the file.

Commonly used rc and. (dot) file name description ~ /. Bash_login please refer to "man bash". If ~ / .bash_profile does not exist, bash treats ~ / .bash_login as ~ / .bash_profile. ~ /. Bash_logout, please refer to "man bash". Referenced by the bash login shell when exiting. ~ / .bash_profile is referenced by bash login shell reference / etc/profile. List of previously executed commands by ~ / .bash_history ~ / .bashrc please refer to "man bash". Referenced by bash non-login interactive shell (no other files). Non-interactive shell does not reference any files unless BASH_ENV or ENV is set. ~ / .emacs is read by emac when it starts. ~ / .forward if an email address is included here, then all messages sent to the owner of ~ will be forwarded to that email address. Configuration files for ~ / .fvwmrc ~ / .fvwm2rcfvwm and fvwm2 (basic X Window Manager). ~ / .hushlogin please refer to "man login". Causes a "silent" login (no email notification, last login information, or MOD information). ~ / .mail.rc mail program user initialization file. Directory of the ncftp/ncftp program; contains bookmarks, logs, macros, preferences, and tracking information. See man ncftp. The purpose of ncftp is to provide a powerful and flexible interface for Internet Standard File transfer Protocol (Internet standard File Transfer Protocol). It is designed to replace the standard ftp program used by the system. ~ / .profile please refer to "man bash". If the ~ / .bash_profile and ~ / .bash_login files do not exist, bash treats ~ / .profile as ~ / .bash_profile and is used by other shell inheriting Bourn. ~ / .pinercPine configuration ~ / .muttrcMutt configuration ~ / .exrc this file controls the configuration of vi.

Example: set ai sm ruler

Writing the above line in this file causes vi to set options such as automatic indentation, matching parentheses, displaying line numbers, and row-columns. ~ / .vimrc default "Vim" configuration file. Same as .exrc. ~ / .gtkrcGNOME toolkit (GNOME Toolkit). ~ / .kdercKDE configuration. ~ /. Netrcftp default login and password. ~ / .rhosts is used by r-tools such as rsh, rlogin, and so on. Because it is easy to impersonate the host, the security is very low.

Must be owned by the user (owner of ~ /) or superuser.

List some hosts from which users can access the account.

If it is a symbolic link, it is ignored.

~ / .rpmrc see "man rpm". If / etc/rpmrc does not exist, it is read by rpm. ~ / .signature message text, which is automatically appended to the end of the message sent from this account. Configuration file for ~ / .twmrctwm (The Window Manager). ~ / .xinitrc is read by X when it starts (not by the xinit script). Programs are usually started.

Example: exec / usr/sbin/startkde

If the above line exists in the file, the line starts the KDE window Manager (KDE Window Manager) when the startx command is issued from this account. ~ / .xmodmaprc this file is transferred to the xmodmap program and can be named any file (for example, ~ / .Xmodmap and ~ / .keymap. Km). ~ / .xserverrc if xinit can find the XJournal xinit to execute, it will run the file as an X server. Default mail history file for ~ / News/Sent-Message-IDsgnus. ~ / .Xauthority is read and written by the xdm program to handle permissions. Refer to the X, xdm, and xauth online help pages. ~ / .Xdefaults, ~ / .Xdefaults-hostname are read by the X application during the startup of the host hostname. If the-hostname file is not found, look for the .Xdefaults file. ~ / .Xmodmap points to .xmodmaprc; Red Hat has a .xinitrc file with that name. ~ / .Xresources is usually the name of the file passed to xrdb to load the X resource database, designed to avoid situations where the application needs to read a long .Xdefaults file. (~ / .Xres has been used in some cases. ) ~ / old mail from mbox users. On how to understand the Linux configuration file to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report