sed -i ‘s/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 100/g;s/^PASS_MIN_LEN.*/PASS_MIN_LEN 8/g;s/^PASS_WARN_AGE.*/PASS_WARN_AGE 10/g‘ /etc/login.defs
注释:
PASS_MAX_DAYS Maximum number of days a password may be used.
PASS_MIN_DAYS Minimum number of days allowed between password changes.
PASS_MIN_LEN Minimum acceptable password length.
PASS_WARN_AGE Number of days warning given before a password expires。。
sed -i ‘2i \auth required pam_tally2.so deny=5 unlock_time=300 even_deny_root root_unlock_time=300\‘ /etc/pam.d/login
sed -i ‘2i \auth required pam_tally2.so deny=5 unlock_time=300 even_deny_root root_unlock_time=300\‘ /etc/pam.d/sshd
sed -i ‘/auth required pam_deny.so/i \auth required pam_tally2.so deny=5 unlock_time=300 even_deny_root root_unlock_time=300\‘ /etc/pam.d/system-auth
注释:
even_deny_root 也限制root用户
deny 用户连续错误登陆的最大次数,超过就锁定该用户
unlock_time 用户锁定后,多长时间解锁,单位秒
root_unlock_time root用户锁定后,多长时间解锁,单位秒
sed -i ‘s/^\(password requisite.*\)/#\1a \npassword requisite pam_cracklib.so try_first_pass retry=5 difok=1 minlen=8 ucredit=-1 lcredit=-1 dcredit=-1/‘ /etc/pam.d/system-auth
注释:
retry=5 允许重试5次;
difok=1 有3个不同字符;
minlen=8 最少长度5位;
ucredit=-1 包含1个大写字母;
lcredit=-1 包含3个小写字母;
dcredit=-1 包含1个数字
ocredit=-1 包含1个特殊符号注意:root用户不受此限制,对之前用户无影响
sed -i ‘s/#PermitRootLogin yes/PermitRootLogin no/‘ /etc/ssh/sshd_config
service sshd restart
systemctl restart sshd
echo ‘export TMOUT=300‘ >> /etc/profile; source /etc/profile
echo ‘HISTSIZE=10000‘ >> /etc/profile; source /etc/profile
在/etc/profile 的文件尾部添加如下行数配置信息
vi /etc/profile
末尾添加:
######jiagu history xianshi#########
USER_IP=`who -u am i 2>/dev/null | awk ‘{print $NF}‘ | sed -e ‘s/[()]//g‘`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="%F %T $USER_IP `whoami` "
shopt -s histappend
export PROMPT_COMMAND="history -a"
######### jiagu history xianshi ##########
#让配置生效
source /etc/profile
grep "/bin/bash$" /etc/passwd |awk -v FS=: ‘{print $1,$7}‘
ps -u 用户名
passwd -S 用户名
passwd -l 用户名
passwd -u 用户名
passwd -d 用户名
passwd -f 用户名
pam_tally2 -u 用户名
pam_tally2 -u 用户名--reset
原文:https://www.cnblogs.com/allan-666/p/14966877.html