(1)这一条登录多少次后就提示并自动结束会话:非常重要,在CentOS6.2中实践Ok,如下:
[root@station90 ssh]# cat /etc/ssh/sshd_config | grep MaxAuth
MaxAuthTries 1 //远程用户通过ssh连接登录2次失败后自动结束会话
The server has disconnected with an error. Server message reads:
A protocol error occurred. Too many authentication failures for root
(2)root只能从tty1和vc登陆。建议仅允许root从一个tty或vc登陆,如果需要更多设备登陆,使用su命令转换为root。
openssh应该禁止使用协议1,禁止root直接登录
/etc/ssh/sshd_config
Protocol 2
MaxAuthTries 1
PermitRootLogin no //不允许root用户使用ssh登录
StrictModes yes
PermitEmptyPasswords no //不允许使用空密码登录
PrintLastLog yes
root不登录,其他用户登录时,添加密码,和用户时的具体操作方法:
useradd jackxiang
忘记了密码,得有root去修改它即可:
jackxiang@192.168.225.128:/root# su root
密码:
root@192.168.225.128:~# passwd jackxiang
更改用户 jackxiang 的密码 。
新的 密码:
service sshd restart
禁止某些用户使用ssh远程登录:
http://www.myhack58.com/Article/48/66/2011/30887.htm
vim /etc/pam.d/sshd
在第一行加入 auth required pam_listfile.so item=user sense=deny file=/etc/sshdusers onerr=succeed,注意一定要在第一行,因为pam中执行顺序是上面优先
vim /etc/sshdusers
在文件中加入root wp ,root 和wp是两个本地用户
service sshd restart
在另一个终端测试
[root@clone2 ~]# ssh clone1.rhel.com
root@clone1.rhel.com's password:
Permission denied, please try again.
root@clone1.rhel.com's password:
Permission denied, please try again.
root@clone1.rhel.com's password:
Permission denied (publickey,gssapi-with-mic,password).
[wp@clone2 ~]$ ssh clone1.rhel.com
wp@clone1.rhel.com's password:
Permission denied, please try again.
wp@clone1.rhel.com's password:
Permission denied, please try again.
wp@clone1.rhel.com's password:
Permission denied (publickey,gssapi-with-mic,password).
两个用户都无法使用ssh了。呵呵,目的达到了
(3)root@192.168.225.128:~# cat /etc/login.defs | grep PASS | grep -v ^#
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
PASS_MAX_DAYS 90 //口令最大使用日期90天
PASS_MIN_DAYS 0 //若设置为2,则设置密码2天后才可以再次更改密码,即密码至少要保留的天数
PASS_MIN_LEN 8 //口令最小长度8位
PASS_WARN_AGE 7 //口令过期前7天警告
(4)
umask至少为027,最好是077
[root@station60 ~]# grep umask /etc/bashrc
umask 077
umask 077
[root@station60 ~]# . /etc/bashrc
[root@station60 ~]# umask
0077
[root@station60 ~]# touch 3.txt
[root@station60 ~]# ll 3.txt
-rw------- 1 root root 0 Apr 8 00:11 3.txt
(5)
检查系统是否最小化安装,启动的运行级别为3
查看/etc/pam.d/su是否包含以下两行
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid //上面的注释已经说的很清楚了,没有注释下面这一行,那么要su到别的用户就必须在wheel组中
(6)关闭telnet服务,redhat默认是关闭telnet服务的
[root@station90 ssh]# netstat -tnlp | grep :23
[root@station90 ssh]# cd /etc/xinetd.d/
[root@station90 xinetd.d]# ls telnet*
ls: telnet*: 没有那个文件或目录
如果有telnet服务,则把该目录下的telnet文件改为disable=yes
[root@station90 xinetd.d]# tail -n 2 /etc/xinetd.d/krb5-telnet | head -n 1
disable = yes
[root@station90 xinetd.d]# service xinetd restart
停止 xinetd: [确定]
启动 xinetd: [确定]
===================================================================================
上面是我从Url:http://lhf0616.blog.51cto.com/2920914/538453 总结的,我贴上原文:
[root@station90 桌面]# awk -F : '($2=="") {print $1}' /etc/shadow //检查空口令帐号
zhang3
[root@station90 桌面]# tail -n 1 /etc/shadow | head -n 1 //-F :是以冒号作为分隔符,($2==""表示第1个和第2个冒号之间是空的,即空口令帐号,{print $1}打印出用户名
zhang3::15071:0:99999:7:::
检查帐号
[root@station90 桌面]# pwck
用户 adm:目录 /var/adm 不存在
用户 news:目录 /etc/news 不存在
用户 uucp:目录 /var/spool/uucp 不存在
用户 gopher:目录 /var/gopher 不存在
用户 pcap:目录 /var/arpwatch 不存在
用户 avahi-autoipd:目录 /var/lib/avahi-autoipd 不存在
用户 oprofile:目录 /home/oprofile 不存在
pwck:无改变
口令复杂度及登录失败策略
应启用登录失败处理功能,可采取结束会话,限制非法登录次数和自动退出措施,口令应有复杂度要求并定期更换
要求强制记住3个密码历史
口令至少包含1个数字,字母和其他特殊字符(如:#,@,!,$等);
5次远程登录失败自动结束会话
[root@station90 桌面]# cat /etc/login.defs | grep PASS | grep -v ^#
PASS_MAX_DAYS 90 //口令最大使用日期90天
PASS_MIN_DAYS 0 //若设置为2,则设置密码2天后才可以再次更改密码,即密码至少要保留的天数
PASS_MIN_LEN 8 //口令最小长度8位
PASS_WARN_AGE 7 //口令过期前7天警告
[root@station90 pam.d]# cat /etc/pam.d/system-auth | tail -n 2 && grep ^#password /etc/pam.d/system-auth
password required pam_cracklib.so difok=3 minlen=8 dcredit=-1,lcredit=-1 ocredit=-1 maxrepeat=3
password required pam_unix.so use_authtok nullok md5
#password requisite pam_cracklib.so try_first_pass retry=3 //注释这一行后,无法修改密码
[root@station90 pam.d]# passwd
Changing password for user root.
passwd: Authentication information cannot be recovered
修改登录失败策略
[root@station90 ssh]# cat /etc/ssh/sshd_config | grep MaxAuth
MaxAuthTries 1 //远程用户通过ssh连接登录2次失败后自动结束会话
[root@station90 ssh]# ssh 192.168.0.90
root@192.168.0.90's password:
Permission denied, please try again.
root@192.168.0.90's password:
Received disconnect from 192.168.0.90: 2: Too many authentication failures for root
关闭telnet服务,redhat默认是关闭telnet服务的
[root@station90 ssh]# netstat -tnlp | grep :23
[root@station90 ssh]# cd /etc/xinetd.d/
[root@station90 xinetd.d]# ls telnet*
ls: telnet*: 没有那个文件或目录
如果有telnet服务,则把该目录下的telnet文件改为disable=yes
[root@station90 xinetd.d]# tail -n 2 /etc/xinetd.d/krb5-telnet | head -n 1
disable = yes
[root@station90 xinetd.d]# service xinetd restart
停止 xinetd: [确定]
启动 xinetd: [确定]
[root@station90 xinetd.d]# chkconfig xinetd on
openssh应该禁止使用协议1,禁止root直接登录
/etc/ssh/sshd_config
Protocol 2
MaxAuthTries 1
PermitRootLogin no //不允许root用户使用ssh登录
StrictModes yes
PermitEmptyPasswords no //不允许使用空密码登录
PrintLastLog yes
[root@station60 init.d]# pwd
/etc/rc.d/init.d
[root@station60 init.d]# chmod -R 750 ./ 也可以直接chmod -R /etc/init.d/*
[root@station60 init.d]# ll | head -n 2
total 644
-rwxr-x--- 1 root root 1566 Jun 8 2009 acpid
umask至少为027,最好是077
[root@station60 ~]# grep umask /etc/bashrc
umask 077
umask 077
[root@station60 ~]# . /etc/bashrc
[root@station60 ~]# umask
0077
[root@station60 ~]# touch 3.txt
[root@station60 ~]# ll 3.txt
-rw------- 1 root root 0 Apr 8 00:11 3.txt
检查系统是否最小化安装,启动的运行级别为3
查看/etc/pam.d/su是否包含以下两行
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid //上面的注释已经说的很清楚了,没有注释下面这一行,那么要su到别的用户就必须在wheel组中
[root@station60 pam.d]# gpasswd -a oracle wheel
Adding user oracle to group wheel
[root@station60 pam.d]# id oracle
uid=500(oracle) gid=500(oracle) groups=500(oracle),0(root),10(wheel) context=system_u:system_r:unconfined_t
[root@station60 pam.d]# id zhang3
uid=501(zhang3) gid=501(zhang3) groups=501(zhang3) context=system_u:system_r:unconfined_t
[root@station60 pam.d]# su - zhang3
[zhang3@station60 ~]$ su - root //以下密码输入都是正确的
Password:
su: incorrect password
[zhang3@station60 ~]$ su - oracle
Password:
su: incorrect password
[zhang3@station60 ~]$ su - oracle
Password:
su: incorrect password
[zhang3@station60 ~]$ su - oracle
Password:
su: incorrect password
[zhang3@station60 ~]$
[oracle@station60 ~]$ su - oracle
Password:
[oracle@station60 ~]$ su - root
Password:
[root@station60 ~]#
操作指南 1.本地登录用户参考配置操作
#cd /etc/profile.d
执行
#vi autologout.sh
加入如下内容:
TMOUT=600
readonly TMOUT
export TMOUT
保存退出,系统将在用户闲置10分钟后自动注销。
2.远程登录用户参考配置操作
#vi /etc/ssh/sshd_config
将以下内容设置为:
ClientAliveInterval 600
ClientAliveCountMax 0
以上表示10分钟闲置后,自动注销并结束会话。
检测方法 1、判定条件
查看帐号超时是否自动注销;
2、检测操作
cat /etc/ssh/sshd_config
检查其中两个参数设置:
ClientAliveInterval 600
ClientAliveCountMax 0
(2)执行:awk -F: '($3 == 0) { print $1 }' /etc/passwd
返回值包括“root”以外的条目,说明有其他超级用户,低于安全要求。
2、检测操作
执行:awk -F: '($3 == 0) { print $1 }' /etc/passwd
返回值包括“root”以外的条目,说明有其他超级用户;
/etc/securetty 文件设置root登陆的tty和vc(虚拟控制台)设备。/etc/securetty 文件被login程序读 (通常 /bin/login)。它的格式是允许的tty和vc列表,注释掉或不出现的设备,不允许root登陆。
vc/1
#vc/2
#vc/3
#vc/4
#vc/5
#vc/6
#vc/7
#vc/8
#vc/9
#vc/10
#vc/11
tty1
#tty2
#tty3
#tty4
#tty5
#tty6
#tty7
#tty8
#tty9
#tty10
#tty11
root只能从tty1和vc登陆。建议仅允许root从一个tty或vc登陆,如果需要更多设备登陆,使用su命令转换为root。
#!/bin/sh
#
export file=/root/Desktop/
- 浏览: 180950 次
- 性别:
- 来自: 上海
最新评论
-
beckdim:
AAAm 写道楼主 ,现在还有weblogic 8.1 sp2 ...
原BEA系列产品下载地址大全(不定期更新) -
AAAm:
楼主 ,现在还有weblogic 8.1 sp2吗? 我真的很 ...
原BEA系列产品下载地址大全(不定期更新) -
beckdim:
java_cd 写道呵呵,怎么走了呢,我才去呵呵,去了哪个部门 ...
在国信朗讯的日子 -
Eagleme:
我试了一下,可是似乎还是不行啊!
The requested resource(/)is not available问题 -
mutoududu1:
试了 没有解决。。只是
The requested reso ...
The requested resource(/)is not available问题
相关推荐
Linux 用户登录失败 N 次锁定用户(几分钟...使用 PAM_TALLY2.SO 或 PAM_TALLY.SO 模块可以限制用户登录失败 N 次锁定用户,几分钟后自动解锁。这可以有效防止 brute-force 攻击和猜测密码,提高 Linux 系统的安全性。
使用 PAM_TALLY2.SO 模块限制用户登录失败 N 次锁定用户(几分钟后自动解锁)需要按照以下步骤进行: 1. 确定使用 PAM_TALLY2.SO 模块还是 PAM_TALLY.SO 模块,如果系统中含有 PAM_TALLY2.SO 模块,则使用 PAM_...
一、使用 PAM_TALLY2.SO 模块限制用户登录失败 N 次锁定用户 PAM_TALLY2.SO 模块是 Linux 系统中的一种 PAM 模块,用于限制用户的登录失败次数。使用 PAM_TALLY2.SO 模块可以限制用户的登录失败次数,如果用户的...
deny 设置普通用户和root用户连续错误登陆的最大次数,超过最大次数,则锁定该用户; unlock_time 设定普通用户锁定后,多少时间后解锁,单位是秒; root_unlock_time 设定root用户锁定后,多少时间后解锁,单位是秒...
Linux 用户登录失败 N 次锁定用户(几分钟后自动解锁) 本文将详细介绍 Linux 系统中用户登录失败 N 次锁定用户的机制,并提供了多种限制用户登录失败次数的方法。 使用 PAM_TALLY2.SO 模块限制用户登录失败 N 次...
主要给大家分享了linux尝试登录失败后锁定用户账户的两种方法,分别是利用pam_tally2模块和pam_faillock 模块实现,文中通过详细的示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
2. 使用PAM_TALLY2.SO模块限制用户登录失败N次锁定用户(几分钟后自动解锁) - 远程SSH登录限制方法: 修改`/etc/pam.d/sshd`配置文件,在`#%PAM-1.0`下方添加以下行,以限制远程SSH登录失败次数: ``` auth ...
本文档将详细讨论Linux环境下通过PAM模块实现的用户登录控制机制,特别是在用户连续登录失败达到一定次数后,系统将自动锁定用户账户,并在一段时间后自动解锁。 首先,PAM(Pluggable Authentication Modules)是...
这里的 `deny=3` 表示用户登陆失败 3 次后将被锁定,`unlock_time=600` 表示锁定后 10 分钟后解锁,`even_deny_root` 表示 root 用户也将被锁定,`root_unlock_time=1200` 表示 root 用户锁定后 20 分钟后解锁。...
针对linux上的用户,如果用户连续3次登录失败,就锁定该用户,几分钟后该用户再自动解锁。Linux有一个pam_tally2.so的PAM模块,来限定用户的登录失败次数,如果次数达到设置的阈值,则锁定用户。 PAM的配置文件介绍...
本文档将详细介绍 Linux 操作系统的安全加固操作手册,涵盖身份鉴别、用户口令安全、口令生存期限制、账号锁定策略等多个方面。 1. 身份鉴别 Linux 操作系统中,身份鉴别是非常重要的一步。空口令用户是非常危险...
- 添加`TMOUT`变量设置登录超时自动退出时间。例如: ```sh TMOUT=600 export TMOUT ``` ##### 5. 密码策略与默认访问权限 - **配置文件**: `/etc/login.defs` - **实现方法**: - 设置密码时效性: - 最小长度...
* 限制登录失败次数:使用 `pam_tally2` 模块来限制登录失败次数,并锁定帐号。 * 解锁用户:使用 `pam_tally2` 模块来解锁用户。 3. 安全的远程管理方式 ------------------------- * 防止鉴别信息在网络传输过程...
- **安全基线项说明**: 针对采用静态口令认证技术的设备,需要设定用户登录失败后的锁定策略。 - **检测步骤**: - 检查`/etc/pam.d/system-auth`文件中的`auth required pam_tally2.so`参数配置。 - 使用命令`cat ...
* 查看登录失败处理功能是否开启:cat /etc/pam.d/system-auth 若没有红框中的内容,则需要添加以开启登录失败处理功能auth required pam_tally2.so deny=3 unlock_time=300 even_deny_root root_unlock_time=10。...
**设置密码输入错误次数限制**:使用`vi /etc/pam.d/common-auth`命令打开配置文件,并添加`auth required pam_tally.so onerr=fail deny=3 unlock_time=300`,表示当用户连续三次输入错误密码后,账号将被锁定五...
- 在单用户模式下,运行`/usr/sbin/pam_tally2 -u root -r`命令解锁root用户的密码锁定次数。 - 连续执行两次该命令,直到Failures次数显示为0,表示解锁成功。 2. **重启系统**: - 使用`exec /sbin/init`命令...
2. **设置失败次数限制**:编辑PAM配置文件,在文件中添加如下行来实现登录失败三次后锁定账户30分钟的功能。 ```bash auth required pam_tally2.so deny=3 unlock_time=300 ``` #### 六、禁止使用重复密码 1. ...
- **登录失败锁定机制**:利用`pam_tally.so`模块实现,当登录失败达到一定次数(如5次)时,锁定账号一段时间(如10分钟)。 - **登录超时设置**: - 通过修改`/etc/profile`中的`TMOUT`变量来控制SSH会话的超时...