#!/bin/bash
# 输入文件和输出文件
input_file="usernames.txt"
output_file="passwords.txt"
# 删除输出文件(如果存在)
rm -f "$output_file"
# 读取用户名,并为每个用户名生成密码并使用 sudo 更改密码
while IFS= read -r username || [[ -n "$username" ]]; do
# 生成随机密码
password=$(cat /dev/urandom | tr -dc '[:alnum:]!@#$%^&*' | fold -w 20 | head -n 1)
echo "Username: $username, Password: $password"
# 写入用户名和密码到输出文件
echo "$username:$password" >> "$output_file"
# 使用 sudo 更改密码
echo "$username:$password" | sudo chpasswd
done < "$input_file"
echo "Passwords have been generated and saved to $output_file, and passwords have been reset using sudo"