#!/bin/bash# This shell script will create amount of Linux login accounts for you.# 1. check the "accountadd.txt" file exist? you mush create that file manually.# one account name one line in the "accountadd.txt" file.# 2. use openssl to create users password.# 3. user must change his password in his first login.# 4. more option.# 2023/11/26 chen pengexportPATH# 0. userinputpwmech="openssl"# 1. check the accountadd.txt fileif[!-f accountadd.txt ];thenecho-e"There is no accountadd.txt file, stop here."exit1firm-f outputpw.txt # clear outputpw.txt to place new account's passwordusernames=$(cat accountadd.txt)forusernamein$usernamesdouseradd-m-s /bin/bash ${username}# new username (default create home directory and use /bin/bash)if["$pwmech"=="openssl"];thenusepw=$(openssl rand -base646)# it will output a random string that's 8 characters long#else# usepw=$usernamefiecho"$username:$usepw"| chpasswd # new password
chage -d0$username# force password changeecho"username=$username, password=$usepw">> outputpw.txt
done