pam基于用户认证限制

限制centos用户只能够在worktime通过ssh远程连接本机
1、 A(172.16.249.206)添加centos用户

[root@husa security]# useradd centos
[root@husa security]# echo “root” | passwd --stdin centos
更改用户 centos 的密码 。
passwd:所有的身份验证令牌已经成功更新。

2、 B(172.16.249.207)另一台主机连接centos用户所在主机

[root@localhost ~]# ssh centos@172.16.249.206

The authenticity of host ‘172.16.249.206 (172.16.249.206)’ can’t be established.
RSA key fingerprint is 36:8e:f5:0e:4a:34:75:e6:69:a7:b6:8b:19:8e:d6:ce.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘172.16.249.206’ (RSA) to the list of known hosts.
centos@172.16.249.206’s password:

[centos@husa ~]$ ifconfig

eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.249.206 netmask 255.255.0.0 broadcast 172.16.255.255
inet6 fe80::20c:29ff:fe4d:a050 prefixlen 64 scopeid 0x20
ether 00:0c:29:4d:a0:50 txqueuelen 1000 (Ethernet)
RX packets 2699445 bytes 234282128 (223.4 MiB)
RX errors 0 dropped 1397 overruns 0 frame 0
TX packets 50290 bytes 49619170 (47.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

3、 在/etc/pam.d/sshd文件中添加一行

account    required     pam_nologin.so
account    required     pam_time.so         #用于配置时间限制
account    include      password-auth

4、 在/etc/security/time.conf文件中添加下面一行

sshd;*;centos;MoTuWeThFr0800-1800   #这里表示centos可以在MoTuWeThFr0800-1800时间段内使用sshd服务从任何终端登录

这个条目还可以有其他的逻辑方式

login & sshd;*;centos;MoTuWeThFr0800-1800   #这里表示使用login或sshd登陆
sshd;*;centos|arch;!MoTuWeThFr0800-1800     #这里表示使用sshd服务的pam机制,在非工作日工作时段使用任何终端,arch和centos登陆

注意:time.conf文件中的条目只能使用一个wildcard

5、 在B主机使用centos用户ssh远程登录

[root@localhost ~]# ssh centos@172.16.249.206
centos@172.16.249.206's password: 
Connection closed by 172.16.249.206

可以发现,虽然账号密码sshd服务都正确,但是仍然不能远程登陆。

限制只有centos组内的用户可通过ssh连接到本机
配置方法差不多,简单过程为:

1、 添加用户到centos组 
2、 在/etc/pam.d/sshd文件中使用account required pam_group.so PAM认证 
3、 在/etc/security/group.conf文件中配置登陆选项 
4、 另一台主机远程登陆

用户连续登陆失败3次以上就禁止登陆
使用pam_tally.so模块

pam_tally.so [ file=/path/to/counter ] [ onerr=[fail|succeed] ] [ magic_root ] [
even_deny_root_account ] [ deny=n ] [ lock_time=n ] [ unlock_time=n ] [ per_user ] [ no_lock_time ]
[ no_reset ] [ audit ]

pam_tally [ --file /path/to/counter ] [ --user username ] [ --reset[=n] ] [ --quiet ]

This module maintains a count of attempted accesses, can reset count on success, can deny access if too
many attempts fail.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值