linux[批量]添加,刪除用戶操作


添加用戶

從文件中讀取將要創建的用戶名

account201.txt 內容:

 

 

 
        
#!/bin/bash

export PATH=/bin:/sbin:/usr/bin:/usr/sbin
# check account.txt is exits
從文件中讀取將要創建的用戶名
account_file="account201.txt"
# 如果文件不存在
if [ ! -f $account_file ]; then
    echo "Don't have accout.txt"
    exit 1
fi

usernames=$( cat $account_file )

for username in $usernames
do
  ·# 添加用戶
    useradd $username
  # 設置 密碼同用戶名
    echo $username:$username | chpasswd
  # 設置新用戶在第一次登陸時自己重置密碼
    chage -d 0 $username
    echo -e "echo -e \"\033[36m made by lsx \033[0m\"" >> /home/$username/.bashrc
done
echo "Create accounts successfully!"

 

 

批量刪除:

del_accounts.txt 內容

 

 

 

#!/bin/bash#houyanzhi create it to delete student's PUTTY accounts last year export PATH=/bin:/sbin:/usr/bin:/usr/sbin # check account.txt is exits account_file="del_account.txt" if [ ! -f $account_file ]; then echo "Don't have accout.txt" exit 1 fi usernames=$( cat $account_file ) for username in $usernames do
  # 刪除語句
userdel -r $username done echo "Delete accounts successfully!"

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM