Skip to content

Eternal Center

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

Category: System User & System Privilege (系统用户 & 系统权限)

Posted on April 11, 2022April 12, 2022

[排错] 解决 Linux 运行 authselect 命令时报错 “[error] [/etc/authselect/system-auth] has unexpected content!” 或者 “[error] [/etc/authselect/password-auth] has unexpected content!”

报错代码:

[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 文件里的所有内容)

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 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 October 10, 2021December 26, 2021

[工具] Shell 批量修改多个远程服务器某一个用户的密码 (精致版)

介绍:

作者:朱明宇
名称:批量修改多个远程服务器某一个用户的密码
作用:批量修改多个远程服务器某一个用户的密码

使用方法:
1. 将此脚本和清单 $list 文件放在同一目录下
2. 清单 $list 里每服务器名占用一行
3. 给脚本分割线里的变量赋值
4. 给此脚本添加执行权限
5. 执行此脚本

脚本分割线里的变量:
1. list=”list.txt” #指定清单的目录和名称
2. user=eternalcenter #指定要修改密码的用户
3. password=eternalcenter #指定要修改的密码

注意:
此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器,并且可以通过 sudo 获得 su 的 root 权限

脚本:

#!/bin/bash

####################### Separator ########################

list="list.txt"
user=eternalcenter
password=eternalcenter

####################### Separator ########################

num=1

cat $list
for i in `cat $list`
do
        echo $num
        echo $i

	ssh -t $i "type lsb_release" &> /dev/null
        if [ $? -ne 0 ]; then
              distribution=`ssh -t $i "cat /etc/*release | grep '^NAME'"`
	      if [ $? -ne 0 ];then
		      distribution=`ssh -t $i "cat /etc/*release"`
	      fi
        else
              distribution=`ssh -t $i "lsb_release -i | grep 'ID' | grep -v 'n/a'"`
        fi;

        echo $distribution

	case $distribution in
		*"RedHat"* | *"Red Hat"*)
		ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
		if [ $? -eq 0 ];then
			echo -e "\033[32m$i is success\033[0m"
		else
			echo -e "\033[31m$i is fail\033[0m"
		fi
		;;

		*"CentOS"*)
		ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
		if [ $? -eq 0 ];then
			echo -e "\033[32m$i is success\033[0m"
		else
			echo -e "\033[31m$i is fail\033[0m"
		fi
		;;

		*"SUSE"* | *"SLES"*)
		ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
		if [ $? -eq 0 ];then
			echo -e "\033[32m$i is success\033[0m"
		else
			echo -e "\033[31m$i is fail\033[0m"
		fi
		;;
               
		*"openSUSE"*)
		ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
		if [ $? -eq 0 ];then
			echo -e "\033[32m$i is success\033[0m"
		else
			echo -e "\033[31m$i is fail\033[0m"
		fi
		;;

		*)
                echo -e "\033[31m$i is fail \033[0m" 
		;;
        esac

        let num++

        echo
done
Posted on June 9, 2021February 3, 2022

[工具] Shell 批量修改多个远程服务器某一个用户的密码 (简单版)

介绍:

作者:朱明宇
名称:批量修改多个远程服务器某一个用户的密码
作用:批量修改多个远程服务器某一个用户的密码,并显示密码更新时间

使用方法:
1. 将此脚本和清单 $list 文件放在同一目录下
2. 清单 $list 里每服务器名占用一行
3. 给脚本分割线里的变量赋值
4. 给此脚本添加执行权限
5. 执行此脚本

脚本分割线里的变量:
1. list=”list.txt” #指定清单的目录和名称
2. user=eternalcenter #指定要修改密码的用户
3. password=eternalcenter #指定要修改的密码

注意:
此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器,并且可以通过 sudo 获得 su 的 root 权限

脚本:

#!/bin/bash

####################### Separator ########################

list="list.txt"
user=eternalcenter
password=eternalcenter

####################### Separator ########################

num=1

cat $list
for i in `cat $list`
do
        echo $num
        echo $i
        ssh -t $i "sudo -u root su - root -c \"echo $password | passwd --stdin $user\""
        ssh -t $i "sudo -u root su - root -c \"echo $user:$password | chpasswd\""
        ssh -t $i sudo -u root su - root -c \"chage -l $user\"
        let num++

        echo
done

Posts navigation

Page 1 Page 2 … Page 5 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