# iftop
(补充:此时会不停地显示系统联通状态,按下 “q” 键后退出)
# iftop
interface: eth0
IP address is: 10.10.10.129
IPv6 address is: fdb2:2c26:f4e4:0:5940:b748:da58:4f3
MAC address is: 00:1c:42:c9:3c:81
# iftop
(补充:此时会不停地显示系统联通状态,按下 “q” 键后退出)
# iftop
interface: eth0
IP address is: 10.10.10.129
IPv6 address is: fdb2:2c26:f4e4:0:5940:b748:da58:4f3
MAC address is: 00:1c:42:c9:3c:81
从 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 登录不受影响)
# 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 登录不受影响)
# 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
从 Rocky 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
# authselect current | awk 'NR == 1 {print $3}' | grep custom/
custom/password-policy
(补充:从这里显示的结果可以看出这里选择的自定义配置文件是 custom/password-policy ,如果没有输出则代表没有选择自定义配置文件)
# authselect check
Current configuration is valid.
(补充:从这里显示的结果可以看出自定义配置文件是生效的)
# 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 秒为例)
(注意:不建议执行此步骤,执行后正常的 SFTP 登陆会被视为登陆失败,不过正常的 SSH 登录不受影响)
# vim /etc/authselect/custom/password-policy/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/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 秒为例)
(注意:不建议执行此步骤,执行后正常的 SFTP 登陆会被视为登陆失败,不过正常的 SSH 登录不受影响)
# vim /etc/authselect/custom/password-policy/password-auth
将以下内容:
......
password requisite pam_pwquality.so ......
......
修改为:
......
password requisite pam_pwquality.so try_first_pass local_users_only enforce-for-root retry=3 ......
......
(补充:这里以登录失败 3 次后提示登录失败为例)
# 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 --force
(
补充:
1) 这里以选择名为 password-policy 的自定义配置文件为例
2) 这里设置了 with-sudo、with-faillock、without-nullok 和 with-mkhomedir 参数
)
(注意:使用了 with-mkhomedir 参数后,会提示需要开启 oddjobd)
# dnf install oddjob ; systemctl enable --now oddjobd.service
# authselect current
(补充:这里以生成并选择名为 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 秒为例)
(注意:不建议执行此步骤,执行后正常的 SFTP 登陆会被视为登陆失败,不过正常的 SSH 登录不受影响)
# vim /etc/authselect/custom/password-policy/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/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"}
......
(
补充:
1) 这里以包括 root 用户每使用密码 SSH 远程登录失败 6 次则被锁定 180 秒
2) 登录失败 3 次后提示登录失败
为例
)
(注意:不建议执行此步骤,执行后正常的 SFTP 登陆会被视为登陆失败,不过正常的 SSH 登录不受影响)
# vim /etc/authselect/custom/password-policy/password-auth
将以下内容:
......
password requisite pam_pwquality.so ......
......
修改为:
......
password requisite pam_pwquality.so try_first_pass local_users_only enforce-for-root retry=3 ......
......
(补充:这里以登录失败 3 次后提示登录失败为例)
# authselect apply-changes
(注意:此步骤会刷新 /etc/authselect/system-auth 配置文件和 /etc/authselect/password-auth 配置文件)
# vim /etc/security/faillock.conf
将以下内容:
......
# deny =
......
# unlock_time =
......
修改为:
......
deny = 6
......
unlock_time = 180
......
(补充:这里以包括 root 用户每使用密码 SSH 远程登录失败 6 次则被锁定 180 秒为例)
(注意:只在 Rocky Linux 8 & RHEL 8 才进行此操作)
# faillock --user root
(补充:这里以显示 root 用户近期输错了几次密码为例)
# faillock --user root --reset
# faillock --reset
# authselect disable-feature with-faillock
# authselect enable-feature with-faillock
https://access.redhat.com/solutions/62949
(步骤略)
# yum -y install certbot
(补充:这里以在 Fedora 35 上安装 certbot 为例)
# certbot certonly --email mingyu.zhu@eternalcenter.com -n --agree-tos --webroot -w /usr/share/nginx/html/ -d eternalcenter.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Requesting a certificate for eternalcenter.com
Performing the following challenges:
http-01 challenge for eternalcenter.com
Using the webroot path /usr/share/nginx/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/eternalcenter.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/eternalcenter.com/privkey.pem
Your certificate will expire on 2022-03-20. To obtain a new or
tweaked version of this certificate in the future, simply run
certbot again. To non-interactively renew *all* of your
certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
(
补充:这里以
1) 使用 mingyu.zhu@eternalcenter.com 邮箱
2) 以非交互式的方式
3) 通过给 /usr/share/nginx/html/ 网站目录里添加验证文件进行验证
4) 给 eternalcenter.com 域名
申请 Let’s Encrypt SSL 证书为例
)
# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
Certificate Name: eternalcenter.com
Serial Number: 3e8cdb74a1abfbf3d535ec1c3f8cb3e4e4c
Key Type: RSA
Domains: eternalcenter.com
Expiry Date: 2022-03-20 13:48:48+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/eternalcenter.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/eternalcenter.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(
补充:
1) /etc/letsencrypt/live/eternalcenter.com/fullchain.pem 是公钥
2) /etc/letsencrypt/live/eternalcenter.com/privkey.pem 是私钥
)
# cat /etc/letsencrypt/renewal/eternalcenter.com.conf
# renew_before_expiry = 30 days
version = 1.20.0
archive_dir = /etc/letsencrypt/archive/eternalcenter.com
cert = /etc/letsencrypt/live/eternalcenter.com/cert.pem
privkey = /etc/letsencrypt/live/eternalcenter.com/privkey.pem
chain = /etc/letsencrypt/live/eternalcenter.com/chain.pem
fullchain = /etc/letsencrypt/live/eternalcenter.com/fullchain.pem
(补充:可以看出 Let’s Encrypt SSL 证书是在过期前 30 天才能更新)
# /usr/bin/certbot renew
(补充:这里以延期 Let’s Encrypt SSL 证书为例)
# crontab -e
添加以下内容:
......
0 0 */30 * * /usr/bin/certbot renew
(补充:这里以每过 30 天的 0 时 0 分延期 Let’s Encrypt SSL 证书为例)
1) 一个域名申请次数不能超过 5 次/周
2) 允许申请失败次数不能超过 5 次/时
3) 属于同一个顶级域名的二级域名申请次数不能超过 20 次/周
4) 申请请求频率不能超过 20 次/秒
5) 一个 IP 地址创建用户个数不能超过 10 个/3 小时
6) 一个用户最多 pending 审核的数不能超过 300 个
# 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 服务器
为例
)