内容一:导出 iptables 防火墙规则
# iptables-save > /root/iptables_save
(补充:这里以将 iptables 防火墙规则导出到 /root/iptables_save 文件为例)
内容二:导入 iptables 防火墙规则
# iptables-restore < /root/iptables_save
(补充:这里以将 /root/iptables_save 文件里的内容导入到 iptables 防火墙为例)
# iptables-save > /root/iptables_save
(补充:这里以将 iptables 防火墙规则导出到 /root/iptables_save 文件为例)
# iptables-restore < /root/iptables_save
(补充:这里以将 /root/iptables_save 文件里的内容导入到 iptables 防火墙为例)
# authselect apply-changes
[error] [/etc/authselect/system-auth] has unexpected content!
[error] [/etc/authselect/password-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
或者:
[error] [/etc/authselect/system-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
或者:
[error] [/etc/authselect/password-auth] has unexpected content!
[error] Unexpected changes to the configuration were detected.
[error] Refusing to activate profile unless those changes are removed or overwrite is requested.
/etc/authselect/system-auth 文件或 /etc/authselect/password-auth 文件是不应该被手动修改的,如果被手动修改了,再使用 authselect select sssd 命令或者 authselect apply-changes 命令时则会有此类报错
# authselect apply-changes
(注意:此方法会刷新 /etc/authselect/system-auth 文件和 /etc/authselect/password-auth 文件里的所有内容)
/var/run/utmp
# who
或者:
# w
或者:
# users
/var/log/wtmp
# last
(注意:last 命令显示用户时最多只会显示前 8 个字符)
或者:
# ac
/var/log/lastlog
# lastlog
/var/log/btmp
# lastb
/var/log/messages
/var/log/secure
# vim /etc/sudoers
或者:
# visudo
添加以下内容:
……
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 system-auth
确保包含以下内容:
auth substack system-auth
account include system-auth
password include system-auth
session include system-auth
# cat /etc/pam.d/sshd | grep password-auth
确保包含以下内容:
auth substack password-auth
account include password-auth
password include password-auth
session include password-auth
# vim /etc/pam.d/system-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 nullok try_first_pass
......
下面添加:
......
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 秒为例)
(
注意:
Rocky Linux 8 & RHEL 8 不建议执行此步骤,执行后 Rocky Linux 8 & RHEL 8 正常的 SFTP 登录会被视为失败,不过正常的 SSH 登录不受影响。若要确保正常 SFTP 登录不被视为失败登录,则需要确保部分内容如下:
# cat /etc/authselect/system-auth
......
auth required pam_faillock.so preauth silent
......
auth required pam_faillock.so authfail
......
account required pam_faillock.so
......
)
# vim /etc/pam.d/system-auth
将以下内容:
......
password requisite pam_pwquality.so ......
......
修改为:
......
password requisite pam_pwquality.so try_first_pass local_users_only enforce-for-root retry=3 ......
......
(补充:这里以登录失败 3 次后提示登录失败为例)
# 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 秒为例)
(
注意:Rocky Linux 8 & RHEL 8 不建议执行此步骤,执行后 Rocky Linux 8 & RHEL 8 正常的 SFTP 登录会被视为错误失败,不过正常的 SSH 登录不受影响。若要确保正常 SFTP 登录不被视为失败登录,则需要确保部分内容如下:
# cat /etc/authselect/password-auth
......
auth required pam_faillock.so preauth silent
......
auth required pam_faillock.so authfail
......
account required pam_faillock.so
......
)
# vim /etc/pam.d/password-auth
将以下内容:
......
password requisite pam_pwquality.so ......
......
修改为:
......
password requisite pam_pwquality.so try_first_pass local_users_only enforce-for-root retry=3 ......
......
(补充:这里以登录失败 3 次后提示登录失败为例)
# vim /etc/security/faillock.conf
将以下内容:
......
# deny =
......
# unlock_time =
......
修改为:
......
deny = 6
......
unlock_time = 180
......
(注意:只在 Rocky Linux 8 & RHEL 8 才进行此操作)
# authconfig --enablefaillock --faillockargs="deny=6 unlock_timeout=180" --update
(
补充:
1) 这里以包括 root 用户每使用密码 SSH 远程登录失败 6 次则被锁定 180 秒
2) 登录失败 3 次后提示登录失败
为例
)
# authconfig --disablefaillock --update
# faillock --user root
(补充:这里以显示 root 用户近期输错了几次密码为例)
# faillock --user root --reset
# faillock --reset
# vim /etc/pam.d/system-auth
在此行:
......
auth required pam_faillock.so preauth silent audit even_deny_root deny=6 unlock_time=180
......
下面添加:
......
auth [success=1 default=ignore] pam_succeed_if.so user in mingyuzhu1:mingyuzhu2:mingyuzhu3
......
(补充:这里以排除用户 zhumingyu1、zhumingyu2 和 zhumingyu3 的输错密码次数限制为例)
(注意:Rocky Linux 8 & RHEL 8 不建议执行此步骤)
# vim /etc/pam.d/password-auth
在此行:
......
auth [default=die] pam_faillock.so authfail audit even_deny_root deny=6 unlock_time=180
......
下面添加:
......
auth [success=1 default=ignore] pam_succeed_if.so user in mingyuzhu1:mingyuzhu2:mingyuzhu3
......
(补充:这里以排除用户 zhumingyu1、zhumingyu2 和 zhumingyu3 的输错密码次数限制为例)
(注意:Rocky Linux 8 & RHEL 8 不建议执行此步骤)
https://access.redhat.com/solutions/62949