Linux-PAM认证(linux认证有用吗)
ahcoder 2025-06-24 11:07 2 浏览
在新主机更改用户密码的时候,经常会出现"passwd: Have exhausted maximum number of retries for service"的报错
[root@10-112-41-157 ~]# echo 'co4lgTdDD3iK7WYEJAyL0KT5pLXS0o3r' | passwd --stdin testpam
Changing password for user testpam.
passwd: Have exhausted maximum number of retries for service
实际之上,可以使用chpasswd命令更改解决,但非明文更改密码无法实现
1.PAM机制
在centos 6中用户的密码权限更变模块主要涉及到PAM(Pluggable Authentication Modules)认证机制,该机制由Sun公司提供,在Linux中,PAM是可动态配置的,本地系统管理员可以自由选择应用程序如何对用户进行身份验证。PAM应用在许多程序与服务上,比如登录程序(login、su)的PAM身份验证(口令认证、限制登录),passwd强制密码,用户进程实时管理,向用户分配系统资源等
点击我:>>centos官方文档说明
2.centos pam配置文件的构成
pam主要由动态库与配置文件构成。/etc/pam.d/目录中定义了各种程序和服务的PAM配置文件,如其中system-auth文件是PAM模块的重要配置文件,它主要负责用户登录系统的身份认证工作,不仅如此,其他的应用程序或服务可以通过include接口来调用它(该文件是system-auth-ac的软链接)。此外password-auth配置文件也是与身份验证相关的重要配置文件,比如用户的远程登录验证(SSH登录)就通过它调用。而模块文件则主要存放于/lib64/security/中
1.配置文件
[root@10-110-122-196 ~]# ll /etc/pam.d/
total 148
-rw-r--r--. 1 root root 272 Oct 18 2014 atd
-rw-r--r--. 1 root root 192 Oct 15 2014 chfn
-rw-r--r--. 1 root root 192 Oct 15 2014 chsh
-rw-r--r-- 1 root root 232 Aug 18 2015 config-util
-rw-r--r--. 1 root root 293 Nov 23 2013 crond
-rw-r--r--. 1 root root 71 Nov 22 2013 cvs
-rw-r--r--. 1 root root 115 Nov 11 2010 eject
lrwxrwxrwx. 1 root root 19 Jan 14 2016 fingerprint-auth -> fingerprint-auth-ac
-rw-r--r--. 1 root root 659 Jan 14 2016 fingerprint-auth-ac
略
2.依赖的模块
[root@10-110-122-196 ~]# ll /lib64/security/
total 808
-rwxr-xr-x 1 root root 18552 Aug 18 2015 pam_access.so
-rwxr-xr-x. 1 root root 7504 Dec 8 2011 pam_cap.so
-rwxr-xr-x 1 root root 10272 Aug 18 2015 pam_chroot.so
-rwxr-xr-x. 1 root root 9216 Nov 11 2010 pam_ck_connector.so
-rwxr-xr-x 1 root root 27080 Aug 18 2015 pam_console.so
-rwxr-xr-x 1 root root 14432 Aug 18 2015 pam_cracklib.so
-rwxr-xr-x 1 root root 10168 Aug 18 2015 pam_debug.so
以下略
3.判断是否使用pam认证
判断一个程序是否使用了pam认证,可以查看其是否有使用pam模块即可
[root@10-110-122-196 pam.d]# ldd /usr/sbin/sshd | grep pam
libpam.so.0 => /lib64/libpam.so.0 (0x00007f3460605000)
[root@10-110-122-196 pam.d]# ldd /usr/bin/passwd | grep pam
libpam_misc.so.0 => /lib64/libpam_misc.so.0 (0x00007fe943edb000)
libpam.so.0 => /lib64/libpam.so.0 (0x00007fe9434f6000)
以上说明sshd和passwd都有使用pam认证
3.pam配置文件的格式语法
<module interface> <control flag> <module name> <module arguments>
详细查看一台主机中的system-auth-ac配置文件
[root@10-110-122-196 pam.d]# cat system-auth-ac
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth required pam_env.so
auth sufficient pam_fprintd.so
auth sufficient pam_unix.so nullok try_first_pass
auth requisite pam_succeed_if.so uid >= 500 quiet
auth required pam_deny.so
account required pam_unix.so
account sufficient pam_localuser.so
account sufficient pam_succeed_if.so uid < 500 quiet
account required pam_permit.so
password requisite pam_cracklib.so retry=3 difok=3 minlen=10 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1 enforce_for_root
password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok
password required pam_deny.so
session optional pam_keyinit.so revoke
session required pam_limits.so
session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session required pam_unix.so
1.模块接口:
2.控制标识:
3.模块参数
这里面主要讲pam_cracklib.so的相关参数,因为用户密码修改主要与此模块相关
注意,以上参数仅对非root用户生效,如果想对root用户生效,需要加入参数enforce_for_root,所以回到文章最初提出的那个异常,root用户因为也被强制生效了,所以无法更改用户密码,去掉该选项即可
4.passwd与chpasswd的区别
因为passwd不能更改密码的时候,可以直接使用chpasswd进行更改
[root@10-110-122-196 pam.d]# ldd /usr/sbin/chpasswd | grep pam
[root@10-110-122-196 pam.d]# ldd /usr/bin/passwd | grep pam
libpam_misc.so.0 => /lib64/libpam_misc.so.0 (0x00007f64dd087000)
libpam.so.0 => /lib64/libpam.so.0 (0x00007f64dc6a2000)
从以上可以看得,chpasswd并未使用pam认证机制,所以在passwd不能修改密码的时候,可以进行密码的修改。
从man中查看两者的区别
NAME
passwd - update user’s authentication tokens
SYNOPSIS
passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [username]
DESCRIPTION
The passwd utility is used to update user’s authentication token(s).
This task is achieved through calls to the Linux-PAM and Libuser API. Essentially, it initializes itself as a "passwd" service with Linux-PAM and utilizes configured password modules to authenticate and then update a user’s password.
NAME
chpasswd - update passwords in batch mode
SYNOPSIS
chpasswd [options]
DESCRIPTION
The chpasswd command reads a list of user name and password pairs from standard input and uses this information to update a group of existing users. Each line is of the format:
user_name:password
By default the supplied password must be in clear-text, and is encrypted by chpasswd. Also the password age will be updated, if present.
The default encryption algorithm can be defined for the system with the ENCRYPT_METHOD variable of /etc/login.defs, and can be overwiten with the -e, -m, or -c options.
chpasswd first update the password in memory, and then commit all the changes to disk if no errors occured for any users.
This command is intended to be used in a large system environment where many accounts are created at a single time.
很显然可以查看得到passwd需要调用linux-PAM,然后调用密码模块,最后更新用户密码。而chpasswd是直接更新用户密码
而chpasswd使用的加密算法可以通过选项进行控制,默认是使用SHA-512算法
从/etc/shadow文件中可以看到用户加密码后的密码
[root@10-110-122-196 pam.d]# cat /etc/shadow
root:$6$hFXXRDb0$jQsZU9Lo8.HeYt4.kGr4QD8eUypaBr6EV403dN1LWBTXChNNXad0sHWl/55T7PiKUwdYoiAyeDt1.xqqf2Pt61:17477:0:99999:7:::
其中第二行中的6,代替加密算法为SHA-512,从系统库文件为GLIBC_2.7起,默认加密算法均为 SHA-512,查看系统库glibc版本方法:
[root@10-110-122-196 pam.d]# strings /lib64/libc.so.6 | grep GLIBC
GLIBC_2.2.5
GLIBC_2.2.6
GLIBC_2.3
GLIBC_2.3.2
GLIBC_2.3.3
GLIBC_2.3.4
GLIBC_2.4
GLIBC_2.5
GLIBC_2.6
GLIBC_2.7
GLIBC_2.8
GLIBC_2.9
GLIBC_2.10
GLIBC_2.11
GLIBC_2.12
GLIBC_PRIVATE
centos6系统以上即为2.12版本
相关推荐
- 卡巴斯基实验室成功将Linux系统的驱动程序移植到“KasperskyOS”
-
据os.kaspersky.com网站8月8日报道,俄罗斯卡巴斯基实验室启动了一个研究项目,将Linux驱动程序移植到卡巴斯基公司自主研发的操作系统KasperskyOS——这是该实验室创建的“安全...
- 服务器程序从 Windows 系统移植到 Linux/x86_64 平台时总是崩溃?
-
清华大学出版社的《高效C/C++调试》一书给出了回答:我们的服务器程序最初是为Windows系统开发的,第一次将它移植到Linux/x86_64平台时,它在回归测试中十次会崩溃八次,且仅在...
- Linux系统的移植和裁剪(linux移植lvgl)
-
本节将嵌入式Linux系统按需求裁剪后移植到ARM处理器中。通过对Linux系统的了解和认识,我们在这里选择Linux4.1.15版本,该版本支持64位处理器,相对于前面几代Linux版本有了更大的提...
- 搭建RISC-V模拟环境(搭建虚拟环境)
-
现在RISC-V在主流操作系统上基本都能模拟了,不过我还是觉得Linux下好用。之前在Mac上想用Linux,基本就是在VirtualBox上创建一个虚拟机,从网上下一个Ubuntu的安装iso,安...
- CPU虚拟化:陷入和模拟(cpu虚拟模式是什么)
-
导读:本文摘自于王柏生、谢广军撰写的《深度探索Linux系统虚拟化:原理与实现》一书,重点讨论了虚拟CPU在Guest模式下运行时,由于运行敏感指令而触发虚拟机退出的典型情况。作者:王柏生、谢广军来源...
- 《模拟山羊》恶搞僵尸主题DLC公布 《DayZ》躺枪!
-
近日,开发商CoffeeStain为我们带来了一个好消息,那就是奇葩游戏《模拟山羊(GoatSIMulator)》僵尸主题DLC“GoatZ”将于5月7日登陆PC,Mac,Linux,iOS和安卓...
- 「精品课程」模拟IC设计进阶(模拟ic设计师怎么样)
-
课程导语模拟集成电路设计最重要的是基础理论知识,基础理论的重要性很多人一开始并没有意识到,工作一段时间,做过几个项目以后就会深有感触。除此之外就是个人的学习能力和分析问题、解决问题的能力,其实这些能力...
- 跨平台神器:在Linux上轻松运行Windows软件的方法大揭秘!
-
Wine始于30年前的一个业余爱好项目,当时Windows3.1及其16位API出现了。在一个简单的“HelloWorld”程序之后,它很快就成功地让Solitaire运行起来。...
- LAMMPS 模拟教程全新发布,助力科研入门分子模拟世界
-
https://arxiv.org/html/2503.14020v1本研究发布了8个层层递进的LAMMPS模拟教学教程,并配套开发了专属图形界面LAMMPS–GUI,显著降低了分子模拟的入门门槛。...
- Linux趣味命令,每一个都能产生炫酷效果(示例)
-
Linux趣味命令,每一个都能产生炫酷的效果:cmatrix:模拟《黑客帝国》中的字符矩阵效果。bashCopycodecmatrixfortune:随机显示一句有趣的引语或笑话。bashCopy...
- 「免费!免费!Chris老师经典模拟课程」CMOS模拟电路设计流程
-
创芯大讲堂为广大学员发福利各位创芯大讲堂的同学们,即日起,凡当月购买大讲堂课程达到300元的同学可以享受创芯大讲堂全场课程8折优惠,凡当月购买创芯大讲堂课程达到500元的同学可以享受创芯大讲堂全场课程...
- Gromacs基本模拟流程(gromacs运行命令)
-
GROMACS是一个使用经典分子动力学理论研究蛋白质动力学的高端的高效的工具。GROMACS是遵守GNU许可的免费软件,可以从以下站点下载:http://www.gromacs.org,并且可以在l...
- 国外友人开创Python模拟登陆神库,完美修改它为咱们所用
-
Awesome-python-login-model是一个国人开发的模拟登陆仓库,在这个仓库上有20几个网站的模拟登陆脚本,你可以基于这个仓库实现的代码做简易的修改,以实现自己的自动化功能。仓库地址...
- 并发模拟的四种方式+工具,超级实用
-
原文链接:https://mp.weixin.qq.com/s/jJDJ8YwmzkKS9KvfMamLWA一、PostmanPostman是一个款http请求模拟工具首先演示一下postman最基本...
- 精选模拟IC设计仿真课程(精选模拟ic设计仿真课程怎么样)
-
课程介绍本系列课程采用屏幕录制视频及操作解说的形式,注重于模拟芯片设计流程中的电路原理图设计、仿真及优化方法、版图设计、寄生参数提取及后仿真优化等的实际操作,在电路设计过程中学习模拟IC设计和验证方法...
- 一周热门
- 最近发表
- 标签列表
-
- linux 远程 (37)
- u盘 linux (32)
- linux 登录 (34)
- linux 路径 (33)
- linux 文件命令 (35)
- linux 是什么 (35)
- linux 界面 (34)
- 查看文件 linux (35)
- linux 语言 (33)
- linux代码 (32)
- linux 查看命令 (33)
- 关闭linux (34)
- root linux (33)
- 删除文件 linux (35)
- linux 主机 (34)
- linux与 (33)
- linux 函数 (35)
- linux .ssh (35)
- cpu linux (35)
- 查看linux 系统 (32)
- linux 防火墙 (33)
- linux 手机 (32)
- linux 镜像 (34)
- linux ip地址 (34)
- linux 用户查看 (33)