Linux系统内部的名称解析与安全认证

我们都知道计算机最喜欢的是数字,而人类喜欢的是语言,所以我们在计算机上运行的进程、定义的用户、端口号、协议、ip地址等都需要转换成数字的形式让计算机明白,在Linux上实现这种功能的框架就是nsswitch。

The Name Service Switch (NSS) is a facility in Unix-like operating systems that provides a variety of sources for common configuration databases and name resolution mechanisms. These sources include local operating system files (such as /etc/passwd, /etc/group, and /etc/hosts), the Domain Name System (DNS), the Network Information Service (NIS), and LDAP.

A system administrator usually configures the operating system‘s name services using the file /etc/nsswitch.conf. This lists databases (such as passwd, shadow and group) and one or more sources for obtaining that information. Examples for sources are files for local files, ldap for the Lightweight Directory Access Protocol, nis for the Network Information Service, nisplus for NIS+, and wins for Windows Internet Name Service.

The nsswitch.conf file has line entries for each service consisting of a database name in the first field, terminated by a colon, and a list of possible source databases mechanisms in the second field. A typical file might look like:

passwd:     files ldap

shadow:     files

group:      files ldap

hosts:      dns nis files

ethers:     files nis

netmasks:   files nis

networks:   files nis

protocols:  files nis

rpc:        files nis

services:   files nis

automount:  files

aliases:    files

The order of the services listed determines in which order NSS will attempt to use those services to resolve queries on the specified database.

哈哈,以上的英语应该不是很难,大家查查单词可以看个明白。我稍微解释一下,nsswitch就像一个过滤器接口或者说是分类处理装置,我们需要用到名称解析功能时,nsswitch会根据/etc/nsswitch.conf文件中定义的条目,选择这个名称通过对应的解析方式进行解析,如:文件、nis服务器、dns服务器、ldap数据库(写性能不好,但读性能高)等。

大家看到在我们的库文件目录中/lib64/libnss*  /usr/lib64/libnss*,nsswitch就是调用这些库来完成不同功能的解析工作的。其中libnss3.so,是对应数据库接口的驱动。

我们的配置文件中也说明了这些模块的作用是调用哪些服务。

这就是定义的方式,其实很简单的。一个条目:功能名称:解析库类型(可以有多个,自左而右优先级依次降低)。

功能名称:

aliases, ethers, group, hosts, netgroup, networks, passwd, protocols, rpm, services, shadow

解析库类型:

files, dns, compat, dbm, hesiod, winbind, wins, nis, nisplus

在解析库查询的返回值:

SUCCESS: service ok, found name
NOTFOUND: service ok, name not found
UNAVAIL: service not avaliable
TRYAGAIN: temporary service failure

默认动作:在第一次遇到SUCCESS状态之后,即return,否则,则continue找后面的解析库。

如果要更改这种动作那么定义[NOTFOUND=return]就直接返回不再找后面的解析库

系统passwd功能名称解析的一次过程:

libnss3.so --> (/etc/nsswitch.conf) --> libnss_files.so --> /etc/passwd

Getent用于通过nsswitch框架解析验证的命令:

好了,nsswitch我们告一段落,接下来我们来说PAM,即Linux上的认证框架。大家应该都听说过"3A"认证服务器,即AAA:分别为Authentication(认证)、Authorization(授权)、Accounting(审计)。当众多应用程序都需要用到认证机制时,认证功能可以由共享库来实现,这个共享库就是通过PAM来实现的。

Linux Pluggable Authentication Modules (PAM) provide dynamic authentication support for applications and services in a Linux system. Linux PAM is evolved from the Unix Pluggable Authentication Modules architecture.

Linux-PAM separates the tasks of authentication into four independent management groups:

account modules check that the specified account is a valid authentication target under current conditions. This may include conditions like account expiration, time of day, and that the user has access to the requested service.

authentication modules verify the user‘s identity, for example by requesting and checking a password or other secret. They may also pass authentication information on to other systems like a keyring.

password modules are responsible for updating passwords, and are generally coupled to modules employed in the authentication step. They may also be used to enforce strong passwords.

session modules define actions that are performed at the beginning and end of sessions. A session starts after the user has successfully authenticated.

稍微解释一下:

账户模块:用于验证输入的账号密码是否正确,时间是否在有效期等。
认证模块:用于验证用户的身份是否是他声称的,通过密码或者其他密钥的方式、其他服务器的认证等。
密码模块:用于更新密码和设定密码的使用强度等。
会话模块:用于设定会话建立的权限内容等,在会话建立之前用户认证成功之后和结束时进行。

PAM调用的模块:

PAM的工作流程:

PAM的配置文件:

/etc/pam.conf:主配置文件

Service  type  control  module-path  module-arguments

/etc/pam.d/*:拆分成每个应用专用的配置文件片断

type  control  module-path  module-arguments

Type:

Control:在type中的四中验证方式直接进行如何协调共同完成最终的认证

稍微解释一下:

Require:此项认证必须通过,具有一票否决权,不管通过不通过都会检查后续认证。
Requisite:此项不通过,直接一票否决,不会在检查其他认证。通过了检查后续认证。
Sufficient:一票通过全,此项通过不再检查其他认证,不通过检查后续认证。
Optional:可选项,当有其它认证方式时此项通过不通过无关紧要,除非只有此项。
Include:在文件中定义认证方式,包含此文件。
Substack:也是包含文件,和include不同的是它表示一个子认证。
Module-path:模块路径,可以是相对路径也可以是绝对路径。
Module-arguments:模块使用的参数。

登录系统的认证方式:

至于每个模块的作用和使用方法可以参考:

模块:

pam_unix.so:在认证时为了兼容在PAM机制实现之前的类UNIX系统的认证方式,使用pam_unix.so模块来实现。

nullok:允许使用空密码

try_first_pass:提示用户输入密码之前,首先检查此前栈中已经得到的密码;

pam_env.so:通过配置文件来为用户设定或撤消环境变量

/etc/security/pam_env.conf

pam_shells.so:检查用户使用的是否为合法shell

/etc/shells

下面是个例子:

如果限制远程登录则需要设定pam_sshd配置文件

pam_limits.so:资源限制

/etc/security/limits.conf

/etc/security/limits.d/*

语法格式:

#<domain>       <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, [email protected] syntax
#        - the wildcard *, fordefault entry
#        - the wildcard %, canbe also used with %group syntax,
#                 for maxloginlimit
#
#<type> can have the two values:
#        - "soft"for enforcing the soft limits
#        - "hard"for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits thecore file size (KB)
#        - data - max datasize (KB)
#        - fsize - maximumfilesize (KB)
#        - memlock - maxlocked-in-memory address space (KB)
#        - nofile - max numberof open file descriptors
#        - rss - max residentset size (KB)
#        - stack - max stacksize (KB)
#        - cpu - max CPU time(MIN)
#        - nproc - max numberof processes
#        - as - address spacelimit (KB)
#        - maxlogins - maxnumber of logins for this user
#        - maxsyslogins - maxnumber of logins on the system
#        - priority - thepriority to run user process with
#        - locks - max numberof file locks the user can hold
#        - sigpending - maxnumber of pending signals
#        - msgqueue - maxmemory used by POSIX message queues (bytes)
#        - nice - max nicepriority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority

Pam_securetty.so:设置安全的登录控制台,可以把root用户的所有远程登录都给去掉,就只能使用sudo了,这样可以更安全

配置文件:/etc/securetty

Pam_time.so:设置可登录的时间段

语法格式:

#      services;ttys;users;times
#
# white space is ignored and lines maybe extended with ‘\\n‘(escaped
# newlines). As should be clear from reading these comments,
# text following a ‘#‘ is ignored to the end of the line.
#
# the combination of individual users/terminals etc is a logic list
# namely individual tokens that are optionally prefixed with ‘!‘(logical
# not) and separated with ‘&‘ (logical and) and ‘|‘ (logicalor).
#
# services
#       is a logic list of PAMservice names that the rule applies to.
#
# ttys
#       is a logic list ofterminal names that this rule applies to.
#
# users
#       is a logic list ofusers or a netgroup of users to whom this
#       rule applies.
#
# NB. For these items the simple wildcard ‘*‘ may be used only once.
#
# times
#       the format here is alogic list of day/time-range
#       entries the days arespecified by a sequence of two character
#       entries, MoTuSa forexample is Monday Tuesday and Saturday. Note
#       that repeated days areunset MoMo = no day, and MoWk = all weekdays
#       bar Monday. The twocharacter combinations accepted are
#
#               Mo Tu We Th FrSa Su Wk Wd Al
#
#       the last two beingweek-end days and all 7 days of the week
#       respectively. As afinal example, AlFr means all days except Friday.
#
#       each day/time-rangecan be prefixed with a ‘!‘ to indicate "anything
#       but"
#
#       The time-range part istwo 24-hour times HHMM separated by a hyphen
#       indicating the startand finish time (if the finish time is smaller
#       than the start time it is deemed to apply onthe following day).
#Example:
#xsh;ttyp*;root;!WdMo0000-2400
时间: 2024-08-09 06:33:09

Linux系统内部的名称解析与安全认证的相关文章

一、Linux系统基础目录名称及功用

Linux操作系统中的主要目录及目录内容,是由文件系统层次结构标准(Filesystem Hierarchy Standard,FHS)定义的,在大多数情况下,他都是一个传统的BSD文件系统层次结构的形式. 1./:根处于Linux文件系统树形结构的最顶端,它是文件系统的入口,所有目录.文件.设备都在根目录之下: 2./bin:该目录存放着系统最常用最重要的命令,是以独立的文件形式存在,这个目录中的文件都是可执行文件并且是普通用户都可以使用的命令,系统最基础的命令都在这里: 3./usr:该目录

linux系统解压缩/压缩命令解析

1)zip与unzip命令 zip -r myfile.zip ./*        将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. unzip -o -d /home/sunny myfile.zip        把myfile.zip文件解压到 /home/sunny/ ,-o:不提示的情况下覆盖文件,-d:指明将文件解压缩到/home/sunny目录下. zip -d myfile.zip smart.txt        删除压缩文

每天进步一点点——Linux系统时间来处理

转载请注明出处:http://blog.csdn.net/cywosp/article/details/25839551 在程序中时间处理往往是一个麻烦的事.Linux系统提供了非常多关于时间处理的函数,我们能够用这些函数来完毕我们所须要的功能.那么在程序中通常会关心哪些时间问题呢? 真实时间:程序执行的时间,即程序启动到程序消亡所用时间或程序执行到如今所经过的时间 进程时间:一个进程所使用的CPU时间总量.适用于对程序.算法性能的检查或优化 本文仅仅关注真实时间的处理与转换 一.Epoch 不

每天进步一点点——Linux系统中的时间处理

转载请说明出处:http://blog.csdn.net/cywosp/article/details/25839551 在程序中时间处理往往是一个麻烦的事,Linux系统提供了很多关于时间处理的函数,我们可以用这些函数来完成我们所需要的功能.那么在程序中一般会关心哪些时间问题呢? 真实时间:程序运行的时间,即程序启动到程序消亡所用时间或程序运行到现在所经过的时间 进程时间:一个进程所使用的CPU时间总量,适用于对程序.算法性能的检查或优化 本文只关注真实时间的处理与转换 一.Epoch 无论地

Linux系统下磁盘配额、软RAID及LVM的配置与管理

Linux系统下磁盘配额.软RAID及LVM的 配置与管理 一.设定文件系统配额 1.概述:配额是操作系统的一个可选的功能, 它允许管理员以文件系统为单元, 限制分派给用户或组成员所使用的磁盘空间大小或是使用的总文件数量.这经常被用于那些分时操作的系统上, 对于这些系统而言, 通常希望限制分派到每一个用户或组的资源总量, 从而可以防止某个用户占用所有可用的磁盘空间. 2.配置文件系统配额(基于用户): (1)配置配额前准备工作: 1)备份/home目录,创建分区,进行挂载,将/home目录下的数

Linux系统(X64)安装Oracle11g完整安装图文教程另附基本操作

一:查看本地ssh服务 Linux系统下安装启动ssh服务,下面以CentOS版本Linux系统为例: 1.检查是否装了SSH包 rpm -qa |grep ssh 2.没有安装SSH直接YUM安装 yum install openssh-server 3.检查SSH服务是否为开机启动 chkconfig --list sshd 4.设置开机启动SSH服务 chkconfig --level 2345 sshd on 5.重新启动下SSH服务 service sshd restart 6.验证是

正确学习Linux系统的5个建议

最近几年Linux系统应用越来越广泛,以至于很多人开始热衷学习Linux.但是我们都是从小都是学习windows系统长大的,从windows 98到现在的windows 10,而根据学习windows系统的经验来学习Linux,使很多人越学越茫然,收效甚微,而不知怎么样才能有效的学习好Linux.下面本人根据自己的经验来给大家说说,怎么样有效的学习Linux系统. 我们学习Linux系统的目标是什么? Linux被当作是一个类Unix的系统,我们学习Linux的相关知识,就可以更好的学习Unix

关于linux系统下的inode

1.查看文件inode stat 1.txt 2.inode是个什么鬼? 一个硬盘的最小存储单位叫”扇区”(sector),一个扇区大小是512个字节 操作系统读取硬盘时,并非一个扇区一个扇区去读取,天哪噜,那也太慢了,而是一次读取n多个扇区,这n多个扇区组成一个”块”(block),最常见的情况是连续8个扇区组成一个块,也就是一个块4k,而”块”就是文件存储的最小单位了. 文件是存到”块”里了,那总得找个地儿来存储文件的一些属性吧,比如作者,大小等等,所以,搞了个叫”索引节点”的东西来存储这些

如何从Linux系统中删除用户账户

在服务器上维护用户就是添加.修改以及删除用户.当一个用户出于某种原因不再需要登录系统时,我们需要删除此用户以避免安全漏洞.在Linux系统上,我们用userdel命令来删除一个用户.推荐学习Linux视频教程. userdel是什么 userdel 是一个底层用于删除用户的工具.在 Debian 上,我们通常会使用 deluser 命令.userdel 会查询系统账户文件,例如 /etc/password 和 /etc/group.那么它会删除所有和用户名相关的条目.在我们删除它之前,用户名必须