Pam的配置过程详解
PAM:可插拔的认证模块 模块 /lib/security 接口文件 /etc/pam.d/ type auth 验证是否有该帐号 account 口令 帐号是否过期 password 用户修改口令 session 会话过程 control required 必须通过, 如果没有通过 ,测底否定 ,而且还要看后续模块 如果通过 ,且还要看后续模块 requisite 必须通过, 如果没有通过 ,测底否定 ,而且不看后续模块 如果通过 ,且还要看后续模块 sufficient 如果没有通过 ,不否定 ,而且看后续模块 只要有一个通过 通过 查看模块 [root@localhost security]# pwd /lib/security [root@localhost security]# ls 1.简单模块的应用 例如 pam_nologin.so 模块 [root@localhost ~]# vim /etc/nologin #不进行任何设置 普通的用户就不能登录了 原因是 [root@localhost pam.d]# pwd /etc/pam.d [root@localhost pam.d]# vim sshd 3 account required pam_nologin.so 查看日志如下: calhost ~]# tail -f /var/log/secure 1:28:44 localhost sshd[5647]: fatal: Access denied for user u1 by PAM account configuration Dec 23 21:28:44 localhost sshd[5646]: Failed password for u1 from 192.168.10.1 port 3486 ssh2 删除rm /etc/nologin 就可以正常登录 2.模块pam_access.so 例子1.限定user1只能从192.168.10.1 ssh [root@localhost security]# pwd /etc/security [root@localhost security]# vim access.conf 25 + : user1 :192.168.10.1 26 - :user1 : all 限定user1可以从任何地方 ssh 其他人(管理员除外)都不可以ssh 查看日志如下: Dec 23 23:17:06 localhost sshd[7256]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=localhost.localdomain user=user1 Dec 23 23:17:09 localhost sshd[7256]: Failed password for user1 from 127.0.0.1 port 44903 ssh2 3.模块pam_limits.so 4.限制用户连接次数 [root@localhost security]# vim limits.conf 49 user1 - maxlogins 2 验证 User1 最多只能连接2个,超过的时候就不能登录上去 查看日志如下 Dec 24 00:03:14 localhost sshd[7958]: pam_limits(sshd:session): Too many logins (max 2) for user1 验证user1 可以通过制定ip登录 其他ip不行 注意:每一次做完限制的时候不要忘了清空规则,以免影响后面的测试。 限定 test user1组用户可以ssh, user2 不属于test组,不可以利用ssh 1.先以vsftpd为例测试某些组的用户不能登录 2.安装vsftpd [root@localhost pam.d]# pwd /etc/pam.d [root@localhost pam.d]# vim vsftpd auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed #在/etc/vsftpd/ftpusers里的用户都不能登录ftpd 将user1 加入ftpuser 测试验证。 测试发现不能登录,新添加的user2 可以登录 查看日志如下: Dec 24 00:38:52 localhost vsftpd: pam_listfile(vsftpd:auth): Refused user user1 for service vsftpd 下面我们做一组能够ssh的用户 指定只有这一组能够通过ssh登录 [root@localhost security]# gpasswd -a user1 test [root@localhost security]# groups user1 user1 : user1 test [root@localhost security]# useradd user2 [root@localhost pam.d]# pwd /etc/pam.d [root@localhost pam.d]# vim sshd session required pam_listfile.so item=group sense=allow file=/etc/allowgroup onerr=succeed 把用户组test添加到/etc/groupallow vim /etc/allowgroup Test 验证如下: User1可以通过ssh登录 user2 不可以通过ssh登录 查看日志如下: Dec 24 01:07:28 localhost sshd[9091]: Accepted password for user1 from 192.168.10.20 port 1066 ssh2 Dec 24 01:08:46 localhost sshd[9130]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.10.20 user=user2 Dec 24 01:08:48 localhost sshd[9130]: Failed password for user2 from 192.168.10.20 port 1067 ssh2 查看本栏目更多精彩内容:http://www.bianceng.cn/OS/Linux/ (编辑:滁州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |