内容一:所有正在登录的用户
/var/run/utmp
内容二:所有的登录和登出记录
/var/log/wtmp
内容三:所有用户最有一次登录记录
/var/log/lastlog
内容四:所有错误登录尝试记录
/var/log/btmp
内容五:所有信息 (其中也包括登录相关的记录)
/var/log/messages
/var/run/utmp
/var/log/wtmp
/var/log/lastlog
/var/log/btmp
/var/log/messages
# vim /etc/sudoers
添加以下内容:
……
zhumingyu ALL=(ALL) /usr/bin/mysql
(补充:这里以给用户 zhumingyu 添加 /usr/bin/mysql 命令为例)
# vim /etc/sudoers
在
......
env_reset
......
这一行下面添加:
......
Defaults env_keep += "http_proxy https_proxy"
......
(补充:这里以允许用户在进行 sudo 提权的同时也能使用 http_proxy、https_proxy 为例)
从 CentOS Linux 8 & RHEL 8 开始,系统的身份验证模块从 CentOS Linux 7 & RHEL 7 的 pam_tally2 换成了 pam_faillock
# vim /etc/ssh/sshd_config
将以下内容:
......
#UsePAM no
......
修改为:
......
UsePAM yes
......
# systemctl restart sshd
# cat /etc/pam.d/login | grep password-auth
auth substack password-auth
account include password-auth
password include password-auth
session include password-auth
(注意:如果输出结果中不包含这 4 条内容则需要手动添加)
# vim /etc/pam.d/password-auth
在
......
auth required pam_env.so
......
这一行下面添加:
......
auth required pam_faillock.so preauth silent audit even_deny_root deny=6 unlock_time=180
......
在
auth sufficient pam_unix.so try_first_pass nullok
这一行下面添加:
......
auth [default=die] pam_faillock.so authfail audit even_deny_root deny=6 unlock_time=180
......
在
account required pam_unix.so
这一行下面添加:
......
account required pam_faillock.so
......
(补充:这里以包括 root 用户每使用密码 ssh 远程登录失败 6 次则被锁定 180 秒为例)
# faillock --user root
(补充:这里以显示 root 用户近期输错了几次密码为例)
# faillock --reset
从 CentOS Linux 8 & RHEL 8 开始,系统的身份验证模块从 CentOS Linux 7 & RHEL 7 的 pam_tally2 换成了 pam_faillock
# vim /etc/ssh/sshd_config
将以下内容:
......
#UsePAM no
......
修改为:
......
UsePAM yes
......
# systemctl restart sshd
# cat /etc/pam.d/sshd | grep password-auth
auth substack password-auth
account include password-auth
password include password-auth
session include password-auth
(注意:如果输出结果中不包含这 4 条内容则需要手动添加)
# authselect current | awk 'NR == 1 {print $3}' | grep custom/
custom/password-policy
(
补充:
(1)如果这条命令里没有输出则代表没有选择自定义认证
(2)从这里的输出结果可以看出这里选择的自定义认证是 custom/password-policy
)
# vim /etc/authselect/custom/password-policy/system-auth
将以下内容:
......
auth required pam_faillock.so preauth silent {include if "with-faillock"}
......
auth required pam_faillock.so authfail {include if "with-faillock"}
......
修改为:
......
auth required pam_faillock.so preauth silent audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
auth required pam_faillock.so authfail audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
(补充:这里以包括 root 用户每使用密码 ssh 远程登录失败 6 次则被锁定 180 秒为例)
# vim /etc/authselect/custom/password-policy/password-auth
将以下内容:
......
auth required pam_faillock.so preauth silent {include if "with-faillock"}
......
auth required pam_faillock.so authfail {include if "with-faillock"}
......
修改为:
......
auth required pam_faillock.so preauth silent audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
auth required pam_faillock.so authfail audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
(补充:这里以包括 root 用户每使用密码 ssh 远程登录失败 6 次则被锁定 180 秒为例)
# authselect apply-changes -b --backup=sssd.backup
(补充:这里以创建 sssd.backup 备份文件为例)
# authselect create-profile password-policy -b sssd --symlink-meta --symlink-pam
(补充:这里以生成名为 password-policy 的自定义认证为例)
# authselect select custom/password-policy with-sudo with-faillock without-nullok with-mkhomedir
(
补充:
1) 这里以选择名为 password-policy 的自定义认证为例
2) 这里设置了 with-sudo、with-faillock、without-nullok 和 with-mkhomedir 参数
)
# authselect current
(补充:这里以生成并选择名为 password-policy 的自定义认证为例)
# vim /etc/authselect/custom/password-policy/password-auth
将以下内容:
......
auth required pam_faillock.so preauth silent {include if "with-faillock"}
......
auth required pam_faillock.so authfail {include if "with-faillock"}
......
修改为:
......
auth required pam_faillock.so preauth silent audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
auth required pam_faillock.so authfail audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
(补充:这里以包括 root 用户每使用密码 ssh 远程登录失败 6 次则被锁定 180 秒为例)
# vim /etc/authselect/custom/password-policy/password-auth
将以下内容:
......
auth required pam_faillock.so preauth silent {include if "with-faillock"}
......
auth required pam_faillock.so authfail {include if "with-faillock"}
......
修改为:
......
auth required pam_faillock.so preauth silent audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
auth required pam_faillock.so authfail audit even_deny_root deny=6 unlock_time=180 {include if "with-faillock"}
......
(补充:这里以包括 root 用户每使用密码 ssh 远程登录失败 6 次则被锁定 180 秒为例)
# authselect apply-changes
(注意:此步骤会刷新 /etc/authselect/system-auth 文件和 /etc/authselect/password-auth 文件)
# faillock --user root
(补充:这里以显示 root 用户近期输错了几次密码为例)
# faillock --reset
# ssh -q -t -t -o StrictHostKeyChecking=no -o ConnectTimeout=5 -l eternalcenter eternalcenter.com
(
补充:这里以
1) 安静模式
2) 打开新端口的模式
3) 不检查服务器记录
4) 超时时间为 5 秒
5) 通过 eternalcenter 用户
6) 登录 eternalcenter.com 服务器
为例
)
# ssh -X eternalcenter@eternalcenter.com
(
补充:这里以
1) 带图形的模式
2) 通过 eternalcenter 用户
3) 登录 eternalcenter.com 服务器
为例
)