Skip to content

Eternal Center

  • System (系统)
  • Services (服务)
  • Databases (数据库)
  • Clusters (集群)
  • Big Data (大数据)
  • Cloud Computing (云计算)
  • Languages (语言)
  • Project (项目)
  • Writings (写作)
  • Eternity (永恒)
  • News (消息)
  • Chronicle (编年史)
  • Words (言)

Category: System Login Security (系统登录安全)

Posted on February 12, 2022February 13, 2022

[内容] Linux 用户登录相关日志

内容一:所有正在登录的用户

/var/run/utmp

内容二:所有的登录和登出记录

/var/log/wtmp

内容三:所有用户最有一次登录记录

/var/log/lastlog

内容四:所有错误登录尝试记录

/var/log/btmp

内容五:所有信息 (其中也包括登录相关的记录)

/var/log/messages
Posted on January 15, 2022January 25, 2022

[步骤] sudo 提权的实现 (sudo 提权的同时可以使用代理) (openSUSE & SLE)

步骤一:给用户添加相应的 sudo 权限

# vim /etc/sudoers

添加以下内容:

……
zhumingyu ALL=(ALL) /usr/bin/mysql

(补充:这里以给用户 zhumingyu 添加 /usr/bin/mysql 命令为例)

步骤二:设置用户使用自己的密码实现 sudo 提权

# vim /etc/sudoers

在

......
env_reset
......

这一行下面添加:

......
Defaults env_keep += "http_proxy https_proxy"
......

(补充:这里以允许用户在进行 sudo 提权的同时也能使用 http_proxy、https_proxy 为例)

Posted on January 2, 2022April 29, 2022

[步骤] Linux 本地和 SSH 输错密码次数的限制 (pam_faillock 版) (CentOS Linux 8 & RHEL 8 版)

步骤目录:

步骤一:背景了解

步骤二:设置 SSH 的登录限制
2.1 在 sshd 中开启 UsePAM
2.1.1 修改 sshd 的配置文件
2.1.2 让修改的 sshd 配置文件生效
2.2 确保 /etc/pam.d/login 包含 password-auth
2.3 添加 pam_faillock 模块

步骤三:远程登录密码输错次数的用户管理
3.1 显示某个用户近期输错了几次密码
3.2 重制所有远程登录密码输错次数

具体的操作步骤:

步骤一:背景了解

从 CentOS Linux 8 & RHEL 8 开始,系统的身份验证模块从 CentOS Linux 7 & RHEL 7 的 pam_tally2 换成了 pam_faillock

步骤二:设置 SSH 的登录限制
2.1 在 sshd 中开启 UsePAM
2.1.1 修改 sshd 的配置文件

# vim /etc/ssh/sshd_config

将以下内容:

......
#UsePAM no
......

修改为:

......
UsePAM yes
......

2.1.2 让修改的 sshd 配置文件生效

# systemctl restart sshd

2.2 确保 /etc/pam.d/login 包含 password-auth

# 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 条内容则需要手动添加)

2.3 添加 pam_faillock 模块

# 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 秒为例)

步骤三:远程登录密码输错次数的用户管理
3.1 显示某个用户近期输错了几次密码

# faillock --user root

(补充:这里以显示 root 用户近期输错了几次密码为例)

3.2 重制所有登录密码输错次数

# faillock --reset
Posted on January 1, 2022April 29, 2022

[步骤] Linux 本地和 SSH 输错密码次数的限制 (pam_faillock 版) (authselect 版) (CentOS Linux 8 & RHEL 8 版)

步骤目录:

步骤一:了解背景

步骤二:设置 SSH 的登录限制
2.1 在 sshd 中开启 UsePAM
2.1.1 修改 sshd 的配置文件
2.1.2 让修改的 sshd 配置文件生效
2.2 确保 /etc/pam.d/sshd 包含 password-auth

步骤三:检查是否选择了 authselect 自定义认证

步骤四:配置认证
4.1 如果 authselect 自定义认证存在
4.1.1 修改 system-auth 文件
4.1.2 修改 password-auth 文件
4.2 如果 authselect 自定义认证不存在
4.2.1 生成新的自定义认证
4.2.1.1 备份当前的自定义认证
4.2.1.2 创建新的自定义认证
4.2.1.3 选择自定义认证
4.2.1.4 显示当前选择的自定义认证
4.2 修改自定义认证
4.2.1 修改 system-auth 文件
4.2.2 修改 password-auth 文件

步骤五:让配置的认证生效

步骤六:管理远程登录密码输错次数的用户
6.1 显示某个用户近期输错了几次密码
6.2 重制所有远程登录密码输错次数

具体的操作步骤:

步骤一:了解背景

从 CentOS Linux 8 & RHEL 8 开始,系统的身份验证模块从 CentOS Linux 7 & RHEL 7 的 pam_tally2 换成了 pam_faillock

步骤二:设置 SSHd 的登录限制
2.1 在 sshd 中开启 UsePAM
2.1.1 修改 sshd 的配置文件

# vim /etc/ssh/sshd_config

将以下内容:

......
#UsePAM no
......

修改为:

......
UsePAM yes
......

2.1.2 让修改 sshd 配置文件生效

# systemctl restart sshd

2.2 确保 /etc/pam.d/sshd 包含 password-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

(注意:如果输出结果中不包含这 4 条内容则需要手动添加)

步骤三:检查是否选择了 authselect 自定义认证

# authselect current | awk 'NR == 1 {print $3}' | grep custom/
custom/password-policy

(
补充:
(1)如果这条命令里没有输出则代表没有选择自定义认证
(2)从这里的输出结果可以看出这里选择的自定义认证是 custom/password-policy
)

步骤四:配置认证
4.1 如果 authselect 自定义认证存在
4.1.1 修改 system-auth 文件

# 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 秒为例)

4.1.2 修改 password-auth 文件

# 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 秒为例)

4.2 如果 authselect 自定义认证不存在
4.2.1 生成新的自定义认证
4.2.1.1 备份当前的自定义认证

# authselect apply-changes -b --backup=sssd.backup

(补充:这里以创建 sssd.backup 备份文件为例)

4.2.1.2 创建新的自定义认证

# authselect create-profile password-policy -b sssd --symlink-meta --symlink-pam

(补充:这里以生成名为 password-policy 的自定义认证为例)

4.2.1.3 选择自定义认证

# 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 参数
)

4.2.1.4 显示当前选择的自定义认证

# authselect current

(补充:这里以生成并选择名为 password-policy 的自定义认证为例)

4.2 修改自定义认证
4.2.1 修改 system-auth 文件

# 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 秒为例)

4.2.2 修改 password-auth 文件

# 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 文件)

步骤六:管理远程登录密码输错次数的用户
6.1 显示某个用户近期输错了几次密码

# faillock --user root

(补充:这里以显示 root 用户近期输错了几次密码为例)

6.2 重制所有远程登录密码输错次数

# faillock --reset
Posted on November 26, 2021April 29, 2022

[命令] Linux 命令 SSH (远程登录)

案例一:脚本中常用的方式

# 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 服务器
为例
)

Posts navigation

Previous page Page 1 Page 2 Page 3 … Page 11 Next page

Aspiration (愿景):

Everyone can achieve self achievement and self happiness fairly

每个人都能公平地实现自我成就和自我幸福

Position (位置):

Running on Evolution Host and DigitalOcean

正在 Evolution Host 和 DigitalOcean 上运行

Logo (徽标):

Additional Information (其他信息):

About Manual Clone Contact Disclaimer Donation Friendly Links 关于 说明书 克隆 联系 免责申明 捐赠 友情链接

Standby IP Address (备用 IP 地址):

152.69.204.95  150.230.63.10  Please configure before use / 请先配置再使用

Search Outside Website (站外搜索):

Google Wikipedia Bing
Proudly powered by LNMP Proudly powered by WordPress