前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Linux】《how linux work》第 七 章 系统配置 系统配置: 日志、系统时间、批处理任务和用户(1)

【Linux】《how linux work》第 七 章 系统配置 系统配置: 日志、系统时间、批处理任务和用户(1)

作者头像
阿东
修改2024-05-06 11:17:20
1090
修改2024-05-06 11:17:20
举报
文章被收录于专栏:《How Linux Work》

第 7 章 系统配置 系统配置: 日志、系统时间、批处理任务和用户

When you first look in the /etc directory, you might feel a bit overwhelmed. Although most of the files that you see affect a system’s operations to some extent, a few are fundamental.

当你第一次查看/etc目录时,可能会感到有点不知所措。

尽管你看到的大部分文件都对系统的运行产生一定的影响,但其中有一些是基础的。

The subject material in this chapter covers the parts of the system that make the infrastructure discussed in Chapter 4 available to the user-level tools covered in Chapter 2. In particular, we’re going to look at the following:

本章的主题材料涵盖了使第4章讨论的基础设施对第2章涵盖的用户级工具可用的系统部分。

特别是,我们将看以下内容:

o Configuration files that the system libraries access to get server and user information o Server programs (sometimes called daemons) that run when the system boots o Configuration utilities that can be used to tweak the server programs and configuration files o Administration utilities

  • 系统库访问的配置文件,用于获取服务器和用户信息
  • 系统启动时运行的服务器程序(有时称为守护进程)
  • 可用于调整服务器程序和配置文件的配置工具
  • 管理工具

As in previous chapters, there is virtually no networking material here because the network is a separate building block of the system. In Chapter 9, you’ll see where the network fits in.

与前几章一样,这里几乎没有涉及网络内容,因为网络是系统的一个独立构建块。

在第9章中,你将看到网络的位置。

7.1 The Structure of /etc(/etc 的结构)

Most system configuration files on a Linux system are found in /etc. Historically, each program had one or more configuration files there, and because there are so many packages on a Unix system, /etc would accumulate files quickly.

Linux系统上的大多数系统配置文件都存放在/etc目录下。

从历史上看,每个程序都有一个或多个配置文件存放在这里,由于Unix系统上有很多软件包,/etc目录下的文件会很快积累起来。

There were two problems with this approach: It was hard to find particular configuration files on a running system, and it was difficult to maintain a system configured this way. For example, if you wanted to change the system logger configuration, you’d have to edit /etc/syslog.conf. But after your change, an upgrade to your distribution could wipe out your customizations.

这种方法存在两个问题:在运行中很难找到特定的配置文件,而且以这种方式配置系统也很难维护。

例如,如果你想要更改系统日志记录器的配置,你需要编辑/etc/syslog.conf。但是,在你进行更改后,系统升级可能会覆盖你的自定义配置。

The trend for many years now has been to place system configuration files into subdirectories under /etc, as you’ve already seen for the boot directories (/etc/init for Upstart and /etc/systemd for systemd). There are still a few individual configuration files in /etc, but for the most part, if you run ls -F /etc, you’ll see that most of the items there are now subdirectories.

多年来的趋势是将系统配置文件放在/etc的子目录下,就像你已经在引导目录(/etc/init用于Upstart和/etc/systemd用于systemd)中看到的那样。尽管/etc目录下仍然有一些个别的配置文件,但大部分情况下,如果你运行ls -F /etc命令,你会发现大部分项目都是子目录。

To solve the problem of overwriting configuration files, you can now place customizations in separate files in the configuration subdirectories, such as the ones in /etc/grub.d.

为了解决配置文件被覆盖的问题,现在你可以将自定义配置放在配置子目录中的单独文件中,比如/etc/grub.d目录中的文件。

What kind of configuration files are found in /etc? The basic guideline is that customizable configurations for a single machine, such as user information (/etc/passwd) and network details (/etc/network), go into /etc. However, general application details, such as a distribution’s defaults for a user interface, don’t belong in /etc. And you’ll often find that noncustomizable system configuration files may be found elsewhere, as with the prepackaged systemd unit files in /usr/lib/systemd.

/etc目录下有哪些类型的配置文件?

基本准则是,适用于单台机器的可定制配置,比如用户信息(/etc/passwd)和网络详细信息(/etc/network),应该放在/etc目录下。

然而,一般的应用程序细节,比如用户界面的发行版默认设置,不应该放在/etc目录下。

而且你经常会发现,不可定制的系统配置文件可能会出现在其他地方,比如/usr/lib/systemd目录下的预打包的systemd单元文件。

You’ve already seen some of the configuration files that pertain to booting. Now we’ll look at a typical system service and how to view and specify its configuration.

你已经看到了一些与引导相关的配置文件。

现在我们将看一下典型的系统服务以及如何查看和指定其配置。

7.2 System Logging(系统日志)

Most system programs write their diagnostic output to the syslog service. The traditional syslogd daemon waits for messages and, depending on the type of message received, funnels the output to a file, the screen, users, or some combination of these, or just ignores it.

大多数系统程序将其诊断输出写入syslog服务。

传统的syslogd守护程序等待消息,并根据接收到的消息类型,将输出导向文件、屏幕、用户或其组合,或者仅忽略它。

7.2.1 The System Logger(系统日志记录器)

The system logger is one of the most important parts of the system. When something goes wrong and you don’t know where to start, check the system log files first. Here is a sample log file message:

系统日志记录器是系统中最重要的部分之一。

当出现问题并且不知道从何处开始时,请首先检查系统日志文件。以下是一个示例日志文件消息:

代码语言:javascript
复制
Aug 19 17:59:48 duplex sshd[484]: Server listening on 0.0.0.0 port 22.

Most Linux distributions run a new version of syslogd called rsyslogd that does much more than simply write log messages to files. For example, you can use it to load a module to send log messages to a database. But when starting out with system logs, it’s easiest to start with the log files normally stored in /var/log. Check out some log files—once you know what they look like, you’ll be ready to find out how they got there.

大多数Linux发行版运行名为rsyslogd的新版本syslogd,它不仅仅将日志消息写入文件。

例如,您可以使用它加载模块将日志消息发送到数据库。

但是,在开始使用系统日志时,最简单的方法是从通常存储在/var/log中的日志文件开始。

查看一些日志文件 - 一旦您知道它们的外观,您就可以准备好了解它们是如何产生的。

Many of the files in /var/log aren’t maintained by the system logger. The only way to know for sure which ones belong to rsyslogd is to look at its configuration file.

/var/log中的许多文件不是由系统日志记录器维护的。

唯一确定属于rsyslogd的文件的方法是查看其配置文件。

7.2.2 Configuration Files(配置文件)

The base rsyslogd configuration file is /etc/rsyslog.conf, but you’ll find certain configurations in other directories, such as /etc/rsyslog.d. The configuration format is a blend of traditional rules and rsyslogspecific extensions. One rule of thumb is that anything beginning with a dollar sign ($) is an extension.

基本的rsyslogd配置文件是/etc/rsyslog.conf,但你会在其他目录中找到特定的配置,比如/etc/rsyslog.d。

配置格式是传统规则和rsyslog特定扩展的混合。

一个经验法则是,以美元符号($)开头的任何内容都是扩展。

A traditional rule has a selector and an action to show how to catch logs and where to send them, respectively. For example:

传统规则有一个选择器和一个动作,用于指示如何捕获日志和将其发送到何处。

例如:

代码语言:javascript
复制
Example 7-1. syslog rules
kern.* /dev/console
*.info;authpriv.none➊ /var/log/messages
authpriv.* /var/log/secure,root
mail.* /var/log/maillog
cron.* /var/log/cron
*.emerg *➋
local7.* /var/log/boot.log

The selector is on the left. It’s the type of information to be logged. The list on the right is the action: where to send the log. Most actions in Example 7-1 are normal files, with some exceptions. For example, /dev/console refers to a special device for the system console, root means send a message to the superuser if that user is logged in, and * means message all users currently on the system. You can also send messages to another network host with @host.

选择器在左边:它是要记录的信息类型。

右边的列表是动作:将日志发送到哪里。

示例7-1中的大多数动作都是普通文件,但也有一些例外情况。

例如,/dev/console指的是系统控制台的特殊设备,root表示如果超级用户已登录,则向超级用户发送消息,而 * 表示向当前系统上的所有用户发送消息。

你还可以使用@host将消息发送到另一台网络主机。

Facility and Priority(设施和优先权)

The selector is a pattern that matches the facility and priority of log messages. The facility is a general category of message. (See rsyslog.conf(5) for a list of all facilities.)

选择器是一个匹配日志消息的设施和优先级的模式。

设施是一种消息的通用类别。

(请参阅rsyslog.conf(5)获取所有设施的列表。)

The function of most facilities will be fairly obvious from their name. For example, the configuration file in Example 7-1 catches messages carrying the kern, authpriv, mail, cron, and local7 facilities. In this same listing, the asterisk at ➋ is a wildcard that catches output related to all facilities.

大多数设施的功能从它们的名称中就可以很明显地看出来。

例如,示例7-1中的配置文件捕捉到了携带kern、authpriv、mail、cron和local7设施的消息

在同一列表中,➋处的星号是一个通配符,可以捕捉到与所有设施相关的输出。

The priority follows the dot (.) after the facility. The order of priorities from lowest to highest is debug, info, notice, warning, err, crit, alert, or emerg.

优先级紧跟在设施后面的点(.)之后。

从最低到最高的优先级顺序是debug、info、notice、warning、err、crit、alert或emerg。

NOTE To exclude log messages from a facility in rsyslog.conf, specify a priority of none, as shown at ➊ in Example 7-1. 注意:要在rsyslog.conf中排除某个设施的日志消息,请指定为none的优先级,如示例7-1中的➊所示。

When you put a specific priority in a selector, rsyslogd sends messages with that priority and all higher priorities to the destination on that line. Therefore, in Example 7-1, the *.info for the line at ➊ actually catches most log messages and puts them into /var/log/messages because info is a relatively low priority.

当您在选择器中放入一个特定的优先级时,rsyslogd会将具有该优先级及更高优先级的消息发送到该行上的目的地。

因此,在示例7-1中,位于➊处的 *.info 实际上捕捉到了大多数日志消息,并将它们放入到/var/log/messages中,因为info是一个相对较低的优先级。

Extended Syntax(扩展语法)

As previously mentioned, the syntax of rsyslogd extends the traditional syslogd syntax. The configuration extensions are called directives and usually begin with a $. One of the most common extensions allows you to load additional configuration files. Check your rsyslog.conf file for a directive like this, which causes rsyslogd to load all .conf files in /etc/rsyslog.d into the configuration:

如前所述,rsyslogd的语法扩展了传统syslogd的语法。

配置扩展被称为指令,通常以$符号开头。

其中最常见的扩展之一允许您加载额外的配置文件。

请检查您的rsyslog.conf文件,查找类似以下指令的内容,它会导致rsyslogd将/etc/rsyslog.d目录中的所有.conf文件加载到配置中:

代码语言:javascript
复制
$IncludeConfig /etc/rsyslog.d/*.conf

Most of the other extended directives are fairly self-explanatory. For example, these directives deal with users and permissions:

其他大多数扩展指令都相当直观。

例如,以下指令处理用户和权限:

代码语言:javascript
复制
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022

NOTE Additional rsyslogd configuration file extensions define output templates and channels. If you need to use them, the rsyslogd(5) manual page is fairly comprehensive, but the web-based documentation is more complete. 注意:额外的rsyslogd配置文件扩展定义了输出模板和通道。 如果您需要使用它们,rsyslogd(5)手册页面非常详尽,但基于网络的文档更完整。

Troubleshooting(故障排除)

One of the easiest ways to test the system logger is to send a log message manually with the logger command, as shown here:

测试系统日志记录器最简单的方法之一是使用logger命令手动发送日志消息,如下所示:

代码语言:javascript
复制
$ logger -p daemon.info something bad just happened

Very little can go wrong with rsyslogd. The most common problems occur when a configuration doesn’t catch a certain facility or priority or when log files fill their disk partitions. Most distributions automatically trim the files in /var/log with automatic invocations of logrotate or a similar utility, but if too many messages arrive in a brief period, you can still fill the disk or end up with a high system load.

rsyslogd很少出现问题。

最常见的问题是配置未捕获特定的设施或优先级,或者日志文件填满了磁盘分区。

大多数发行版会自动使用logrotate或类似实用程序来修剪/var/log中的文件,但如果在短时间内收到太多消息,仍然可能会填满磁盘或导致系统负载过高。

NOTE The logs caught by rsyslogd are not the only ones recorded by various pieces of the system. We discussed the startup log messages captured by systemd and Upstart in Chapter 6, but you’ll find many other sources, such as the Apache Web server, which normally records its own access and error logs. To find those logs, see the server configuration. 注意:rsyslogd捕获的日志不是系统中各个组件记录的唯一日志。 我们在第6章中讨论了systemd和Upstart捕获的启动日志消息,但您还会找到许多其他来源,例如通常会记录自己的访问和错误日志的Apache Web服务器。 要找到这些日志,请参阅服务器配置。

Logging: Past and Future(日志记录:过去与未来)

The syslog service has evolved over time. For example, there was once a daemon called klogd that trapped kernel diagnostic messages for syslogd. (These messages are the ones you see with the dmesg command.) This capability has been folded into rsyslogd.

syslog服务随着时间的推移发生了变化。

例如,曾经有一个名为klogd的守护程序,用于捕获用于syslogd的内核诊断消息。

(这些消息是您使用dmesg命令看到的消息。)这个功能已经合并到rsyslogd中。

It’s a near certainty that Linux system logging will change in the future. Unix system logging has never had a true standard, but efforts are underway to change that.

可以几乎确定,Linux系统日志记录将来会发生变化。

Unix系统日志记录从来没有真正的标准,但正在进行努力来改变这一点。

7.3 User Management Files(用户管理文件)

Unix systems allow for multiple independent users. At the kernel level, users are simply numbers (user IDs), but because it’s much easier to remember a name than a number, you’ll normally work with usernames (or login names) instead of user IDs when managing Linux. Usernames exist only in user space, so any program that works with a username generally needs to be able to map the username to a user ID if it wants to refer to a user when talking to the kernel.

Unix系统允许多个独立用户。

在内核级别上,用户仅仅是一个数字(用户ID),但是因为记住名字比数字更容易,所以在管理Linux时通常使用用户名(或登录名)而不是用户ID。

用户名只存在于用户空间中,因此任何与用户名相关的程序如果想要与内核交流时引用用户,通常需要能够将用户名映射到用户ID。

7.3.1 The /etc/passwd File(/etc/passwd 文件)

The plaintext file /etc/passwd maps usernames to user IDs. It looks something like this:

明文文件 /etc/passwd 将用户名映射到用户 ID。它看起来像这样

Example 7-2. A list of users in /etc/passwd

例 7-2. /etc/passwd 中的用户列表

代码语言:javascript
复制
root:x:0:0:Superuser:/root:/bin/sh
daemon:*:1:1:daemon:/usr/sbin:/bin/sh
bin:*:2:2:bin:/bin:/bin/sh
sys:*:3:3:sys:/dev:/bin/sh
nobody:*:65534:65534:nobody:/home:/bin/false
juser:x:3119:1000:J. Random User:/home/juser:/bin/bash
beazley:x:143:1000:David Beazley:/home/beazley:/bin/bash

Each line represents one user and has seven fields separated by colons. The fields are as follows:

每一行代表一个用户,由冒号分隔的七个字段组成。字段如下:

o The username. o The user’s encrypted password. On most Linux systems, the password is not actually stored in the passwd file, but rather, in the shadow file (see 7.3.3 The /etc/shadow File). The shadow file format is similar to that of passwd, but normal users do not have read permission for shadow. The second field in passwd or shadow is the encrypted password, and it looks like a bunch of unreadable garbage, such as d1CVEWiB/oppc. (Unix passwords are never stored as clear text.) An x in the second passwd file field indicates that the encrypted password is stored in the shadow file. A star (*) indicates that the user cannot log in, and if the field is blank (that is, you see two colons in a row, like ::), no password is required to log in. (Beware of blank passwords. You should never have a user without a password.) o The user ID (UID), which is the user’s representation in the kernel. You can have two entries with the same user ID, but doing this will confuse you, and your software may mix them up as well. Keep the user ID unique. o The group ID (GID). This should be one of the numbered entries in the /etc/group file. Groups determine file permissions and little else. This group is also called the user’s primary group. o The user’s real name (often called the GECOS field). You’ll sometimes find commas in this field, denoting room and telephone numbers. o The user’s home directory. o The user’s shell (the program that runs when the user runs a terminal session).

o 用户名。

o 用户的加密密码。在大多数Linux系统中,密码实际上并不存储在passwd文件中,而是存储在shadow文件中(参见7.3.3节“/etc/shadow文件”)。

shadow文件的格式与passwd类似,但普通用户没有对shadow的读取权限。

passwd或shadow文件的第二个字段是加密密码,它看起来像一堆无法读取的垃圾,例如d1CVEWiB/oppc

(Unix密码从不以明文形式存储。)在第二个passwd文件字段中的x表示加密密码存储在shadow文件中。星号(*)表示用户无法登录,如果字段为空(即连续两个冒号,如::),则登录时不需要密码。

(注意空密码。您永远不应该有一个没有密码的用户。)

o 用户ID(UID),它是用户在内核中的表示。您可以有两个具有相同用户ID的条目,但这样做会使您混淆,并且您的软件也可能混淆它们。保持用户ID唯一。

o 组ID(GID)。这应该是/etc/group文件中的一个编号条目。组确定文件权限,除此之外几乎没有其他作用。这个组也被称为用户的主要组。

o 用户的真实姓名(通常称为GECOS字段)。您有时会在该字段中找到逗号,表示房间号码和电话号码。

o 用户的主目录。

o 用户的shell(当用户运行终端会话时运行的程序)。

Figure 7-1 identifies the various fields in one of the entries in Example 7-2.

图7-1标识了示例7-2中一个条目中的各个字段。

Figure 7-1. An entry in the password file

Figure 7-1. An entry in the password file

图 7-1. 密码文件中的条目

The /etc/passwd file syntax is fairly strict, allowing for no comments or blank lines.

/etc/passwd 文件语法相当严格,不允许有注释或空行。

NOTE A user in /etc/passwd and a corresponding home directory are collectively known as an account. 注意 /etc/passwd 中的用户和相应的主目录统称为账户。

7.3.2 Special Users(特殊用户)

You will find a few special users in /etc/passwd. The superuser (root) always has UID 0 and GID 0, as in Example 7-2. Some users, such as daemon, have no login privileges. The nobody user is an underprivileged user. Some processes run as nobody because the nobody user cannot write to anything on the system.

在/etc/passwd文件中,您会发现一些特殊用户。

超级用户(root)的UID和GID始终为0,就像示例7-2中一样。

一些用户,比如daemon,没有登录权限。

nobody用户是一个非特权用户。

一些进程以nobody身份运行,因为nobody用户无法对系统上的任何内容进行写操作。

The users that cannot log in are called pseudo-users. Although they can’t log in, the system can start processes with their user IDs. Pseudo-users such as nobody are usually created for security reasons.

无法登录的用户被称为伪用户。

虽然他们无法登录,但系统可以使用他们的用户ID启动进程。

通常出于安全原因,会创建伪用户,比如nobody。

7.3.3 The /etc/shadow File(/etc/shadow文件)

The shadow password file (/etc/shadow) on a Linux system normally contains user authentication information, including the encrypted passwords and password expiration information that correspond to the users in /etc/passwd.

Linux系统上的阴影密码文件(/etc/shadow)通常包含用户认证信息,包括与/etc/passwd中的用户对应的加密密码和密码过期信息。

The shadow file was introduced to provide a more flexible (and more secure) way of storing passwords. It included a suite of libraries and utilities, many of which were soon replaced by pieces of PAM (see 7.10 PAM). Rather than introduce an entirely new set of files for Linux, PAM uses /etc/shadow, but not certain corresponding configuration files such as /etc/login.defs.

阴影文件的引入提供了一种更灵活(且更安全)的密码存储方式。

它包含了一套库和实用程序,其中许多很快被PAM的一些组件所取代(参见7.10 PAM)。

为了不引入全新的文件集合到Linux中,PAM使用了/etc/shadow,但并不使用一些对应的配置文件,比如/etc/login.defs。

7.3.4 Manipulating Users and Passwords(操作用户和密码)

Regular users interact with /etc/passwd using the passwd command. By default, passwd changes the user’s password, but you can also use -f to change the user’s real name or -s to change the user’s shell to one listed in /etc/shells. (You can also use the commands chfn and chsh to change the real name and shell.) The passwd command is an suid-root program, because only the superuser can change the /etc/passwd file.

普通用户通过使用passwd命令与/etc/passwd进行交互。

默认情况下,passwd命令用于更改用户的密码,但您也可以使用-f选项来更改用户的真实姓名,或者使用-s选项将用户的shell更改为/etc/shells中列出的shell之一。

(您还可以使用chfn和chsh命令来更改真实姓名和shell。)passwd命令是一个suid-root程序,因为只有超级用户才能更改/etc/passwd文件。

Changing /etc/passwd as the Superuser(以超级用户身份更改 /etc/passwd)

Because /etc/passwd is plaintext, the superuser may use any text editor to make changes. To add a user, simply add an appropriate line and create a home directory for the user; to delete, do the opposite. However, to edit the file, you’ll most likely want to use the vipw program, which backs up and locks /etc/passwd while you’re editing it as an added precaution. To edit /etc/shadow instead of /etc/passwd, use vipw -s. (You’ll likely never need to do this, though.)

因为/etc/passwd是明文文件,超级用户可以使用任何文本编辑器进行更改。

要添加用户,只需添加一行适当的内容并为用户创建一个主目录;要删除用户,执行相反的操作。

然而,要编辑该文件,您最可能想使用vipw程序,它在您编辑时备份并锁定/etc/passwd作为额外的预防措施。

要编辑/etc/shadow而不是/etc/passwd,请使用vipw -s。

(尽管您可能永远不需要这样做。)

Most organizations frown on editing passwd directly because it’s too easy to make a mistake. It’s much easier (and safer) to make changes to users using separate commands available from the terminal or through the GUI. For example, to set a user’s password, run passwd user as the superuser. Use adduser and userdel to add and remove users.

大多数组织不赞成直接编辑passwd,因为很容易出错。

使用终端或图形界面提供的单独命令进行用户更改要容易得多(也更安全)。

例如,要设置用户的密码,请以超级用户身份运行passwd user命令。

使用adduser和userdel命令来添加和删除用户。

7.3.5 Working with Groups(与小组合作)

Groups in Unix offer a way to share files with certain users but deny access to all others. The idea is that you can set read or write permission bits for a particular group, excluding everyone else. This feature was once important because many users shared one machine, but it’s become less significant in recent years as workstations are shared less often.

The /etc/group file defines the group IDs (such as the ones found in the /etc/passwd file). Example 7-3 is an example.

Example 7-3. A sample /etc/group file

Unix中的组提供了一种与特定用户共享文件但拒绝其他用户访问的方式。

其思想是您可以为特定组设置读取或写入权限位,排除其他所有人。

这个功能曾经非常重要,因为许多用户共享一台机器,但随着工作站共享的减少,它在近年来变得不那么重要了。

/etc/group文件定义了组ID(例如在/etc/passwd文件中找到的组ID)。示例7-3是一个示例。

示例7-3. 一个示例的/etc/group文件

代码语言:javascript
复制
root:*:0:juser
daemon:*:1:
bin:*:2:
sys:*:3:
adm:*:4:
disk:*:6:juser,beazley
nogroup:*:65534:
user:*:1000:

Like the /etc/passwd file, each line in /etc/group is a set of fields separated by colons. The fields in each entry are as follows, from left to right:

o The group name. This appears when you run a command like ls -l. o The group password. This is hardly ever used, nor should you use it (use sudo instead). Use * or any other default value. o The group ID (a number). The GID must be unique within the group file. This number goes into a user’s group field in that user’s /etc/passwd entry. o An optional list of users that belong to the group. In addition to the users listed here, users with the corresponding group ID in their passwd file entries also belong to the group.

Figure 7-2 identifies the fields in a group file entry.

与/etc/passwd文件类似,/etc/group中的每一行都是由冒号分隔的一组字段。每个条目中的字段从左到右依次是:

o 组名。当您运行类似ls -l的命令时会显示该组名。

o 组密码。几乎不会使用,也不应该使用(应使用sudo代替)。

可以使用*或任何其他默认值。

o 组ID(一个数字)。组ID必须在组文件中是唯一的。

此数字会填入用户的组字段中,该字段位于用户的/etc/passwd条目中。

o 可选的属于该组的用户列表。除了在此处列出的用户之外,具有相应组ID的用户也属于该组。

图7-2标识了组文件条目中的字段。

Figure 7-2. An entry in the group file

Figure 7-2. An entry in the group file

图7-2. 组文件中的一个条目

To see the groups you belong to, run groups.

要查看您所属的组,请运行groups命令。

NOTE Linux distributions often create a new group for each new user added, with the same name as the user. 注意:Linux发行版通常会为每个新添加的用户创建一个与用户名相同的新组。

7.4 getty and login(获取并登录)

getty is a program that attaches to terminals and displays a login prompt. On most Linux systems, getty is uncomplicated because the system only uses it for logins on virtual terminals. In a process listing, it usually looks something like this (for example, when running on /dev/tty1):

getty是一个程序,它连接到终端并显示登录提示符。

在大多数Linux系统中,getty非常简单,因为系统只在虚拟终端上使用它进行登录。

在进程列表中,它通常看起来像这样(例如,在/dev/tty1上运行时):

代码语言:javascript
复制
$ ps ao args | grep getty
/sbin/getty 38400 tty1

In this example, 38400 is the baud rate. Some getty programs don’t need the baud rate setting. (Virtual terminals ignore the baud rate; it’s only there for backward compatibility with software that connects to real serial lines.)

在这个例子中,38400是波特率。

有些getty程序不需要波特率设(虚拟终端忽略波特率;它只是为了向连接到真实串行线路的软件提供向后兼容性。)

After you enter your login name, getty replaces itself with the login program, which asks for your password. If you enter the correct password, login replaces itself (using exec()) with your shell. Otherwise, you get a “Login incorrect” message.

在输入登录名后,getty会用登录程序替换自己,该程序会要求您输入密码。

如果您输入正确的密码,登录程序会用您的shell替换自己(使用exec())。

否则,您会收到“登录失败”的消息。

You now know what getty and login do, but you’ll probably never need to configure or change them. In fact, you’ll rarely even use them, because most users now log in either through a graphical interface such as gdm or remotely with SSH, neither of which uses getty or login. Much of the login program’s real authentication work is handled by PAM (see 7.10 PAM).

现在您知道getty和login的作用了,但您可能永远不需要配置或更改它们。

实际上,您很少使用它们,因为大多数用户现在通过图形界面(如gdm)或通过SSH远程登录,这两种方式都不使用getty或login。

登录程序的大部分身份验证工作都由PAM处理(参见7.10 PAM)。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-04-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 懒时小窝 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 第 7 章 系统配置 系统配置: 日志、系统时间、批处理任务和用户
  • 7.1 The Structure of /etc(/etc 的结构)
  • 7.2 System Logging(系统日志)
    • 7.2.1 The System Logger(系统日志记录器)
      • 7.2.2 Configuration Files(配置文件)
        • Logging: Past and Future(日志记录:过去与未来)
        • 7.3 User Management Files(用户管理文件)
          • 7.3.1 The /etc/passwd File(/etc/passwd 文件)
            • 7.3.2 Special Users(特殊用户)
              • 7.3.3 The /etc/shadow File(/etc/shadow文件)
                • 7.3.4 Manipulating Users and Passwords(操作用户和密码)
                  • 7.3.5 Working with Groups(与小组合作)
                  • 7.4 getty and login(获取并登录)
                  相关产品与服务
                  多因子身份认证
                  多因子身份认证(Multi-factor Authentication Service,MFAS)的目的是建立一个多层次的防御体系,通过结合两种或三种认证因子(基于记忆的/基于持有物的/基于生物特征的认证因子)验证访问者的身份,使系统或资源更加安全。攻击者即使破解单一因子(如口令、人脸),应用的安全依然可以得到保障。
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档