linux安全 Linux

mowen 2024-08-22 309

查看root权限账户

awk -F: '($3==0)' /etc/passwd


查看bash权限账户

cat /etc/passwd|grep bash


查看历史登陆失败ip记录

lastb|sort


查看历史登陆成功ip记录

last|sort


查看所有账号最近登录的ip记录

lastlog


查看验证日志

grep 'sshd:' /var/log/auth.log


Debian/Ubuntu设置在900秒内连续输错2次密码后锁定账户600秒,参考


1、编辑common-auth

vim /etc/pam.d/common-auth
auth required pam_faillock.so preauth audit silent deny=2 even_deny_root
# /etc/pam.d/common-auth - authentication settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authentication modules that define
# the central authentication scheme for use on the system
# (e.g., /etc/shadow, LDAP, Kerberos, etc.).  The default is to use the
# traditional Unix authentication mechanisms.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules.  See
# pam-auth-update(8) for details.
# here are the per-package modules (the "Primary" block)
auth    [success=1 default=ignore]      pam_unix.so nullok
auth [default=die] pam_faillock.so authfail audit deny=2 even_deny_root
auth sufficient pam_faillock.so authsucc audit deny=2 even_deny_root
# here's the fallback if no module succeeds
auth    requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
auth    required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
auth    optional                        pam_cap.so
# end of pam-auth-update config
pam_faillock.so:位于/usr/lib64/security/下;
deny:设置普通用户和root用户连续错误登陆的最大次数,超过最大次数,则锁定该用户;
fail_interval=n:用户帐户锁定必须连续发生身份验证失败的时间间隔长度为 n 秒。默认值为 900(15 分钟);
unlock_time=n:锁定后 n 秒后将重新启用访问。默认值为 600(10 分钟);
even_deny_root:root帐户可以像普通帐户一样被锁定;
root_unlock_time=m:此选项表示设置even_deny_root选项在账户被锁定后,允许 n 秒后访问 root 账户。如果未指定选项,则该值与unlock_time选项的值相同;


2、编辑common-account

vim /etc/pam.d/common-account
# /etc/pam.d/common-account - authorization settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authorization modules that define
# the central access policy for use on the system.  The default is to
# only deny service to users whose accounts are expired in /etc/shadow.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules.  See
# pam-auth-update(8) for details.
#
# here are the per-package modules (the "Primary" block)
account [success=1 new_authtok_reqd=done default=ignore]        pam_unix.so 
# here's the fallback if no module succeeds
account requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
account required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
# end of pam-auth-update config
account required pam_faillock.so


3、重启ssh

systemctl restart sshd


4、查看密码输入错误记录,相同账户出现前面设置的deny次失败记录即锁定账户

faillock


5、重置锁定记录

faillock --user root --reset


最新回复 (0)
返回
发新帖
X