Linux 批量增加新用户

脚本目录下需要有host.txt 用于存储linux主机的IP

 

#!/bin/sh
# Author: ID404


username="ubuntu"
password="1234"
timeout=3
port=22

newuser="newuser"
newpass="newpass"

login(){
    for host in $(cat host.txt);
    do
        sshpass -p "$password" ssh -p $port -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$host "echo -e '$password\n' | sudo -S useradd -s '/bin/bash' -m -G adm,sudo $newuser"
        sshpass -p "$password" ssh -p $port -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$host "echo -e '$password\n' | sudo -S sudo gpasswd -a $newuser sudo"
        sshpass -p "$password" ssh -p $port -o StrictHostKeyChecking=no -o ConnectTimeout=$timeout $username@$host "echo -e '$password\n$newpass\n$newpass\n' | sudo -S passwd $newuser"
        #sleep 3
    done
    echo ""
}

login

 

posted @ 2022-04-13 14:54  id404  阅读(90)  评论(0编辑  收藏  举报