Beruflich Dokumente
Kultur Dokumente
Search...
Tutorial search
Ad Scan your Web-Server for Malware with ISPProtect now. Get Free Trial.
On this page
Create Users And Change Passwords With A
Bash Script Create Users And Change Passwords With A Bash Script
These two scripts are very important for the system admin who regularly
works with mail servers and somehow forgets to backup his system username and password! Let’s say somehow we lost the usernames and
passwords of the mail server. In this case the admin has to manually create all the users and then change the passwords for all the users.
Tedious job. Let’s make our life easier.
First create a file which contains all the user name. Something like this:
nurealam
nayeem
mrahman
farid
rubi
sankar
https://www.howtoforge.com/user_password_creating_with_a_bash_script 1/12
8/13/2018 Create Users And Change Passwords With A Bash Script
Save the file as userlist.txt. Now create the following bash file:
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done
./userlist.txt
This will add all the users to the system. Now we have to change the passwords. Let's say we want username123 as password. So for user
nayeem the password will be nayeem123, rubi123 for user rubi and so on.
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "User $username’s password changed!"
done
https://www.howtoforge.com/user_password_creating_with_a_bash_script 2/12
8/13/2018 Create Users And Change Passwords With A Bash Script
Suggested articles
https://www.howtoforge.com/user_password_creating_with_a_bash_script 3/12
8/13/2018 Create Users And Change Passwords With A Bash Script
20 Comment(s)
Add comment
Name * Email *
p
Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms
Comments
From: Reply
Just something that should be considered. Force all your users to change their passwords because the temporary password is a security risk
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i | change -d 0 "$i"
https://www.howtoforge.com/user_password_creating_with_a_bash_script 4/12
8/13/2018 Create Users And Change Passwords With A Bash Script
You might want to check what you have written in the article as you would not want to save your bash script and then try and execute a file
containing usernames.
chmod 755 userlist.txt
Now run the file:
./userlist.txt
;)
want to create multiple users with in /home with dir same as username and set permisson for every user to there respective dir.
want to set password for all user same as i need how to do it for multiple users in this script
https://www.howtoforge.com/user_password_creating_with_a_bash_script 5/12
8/13/2018 Create Users And Change Passwords With A Bash Script
# which passwd
/usr/bin/passwd
There is some problem in the password script, I have checked with the below script it's working fine.
#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd "$i" --stdin
echo; echo "User $username's password changed!"
done
Regards,
Ankur
https://www.howtoforge.com/user_password_creating_with_a_bash_script 6/12
8/13/2018 Create Users And Change Passwords With A Bash Script
you need to make few changes like inside the bash file theire is adduser line, replace it with useradd and run script as "sh sciptname.sh" in
case you are working with redhat linux.
Thanks.
Excellent! I had used a script to create multiple users, but I forgot to include passwords in the script. Your script helped me change their
passwords on multiple servers. Thanks for posting this.
Give me steps how to created the commentline for the different users in this same script?
so all this info is good to know, but my question is what syntax do i use to create a script that prints all the data from
/etc/passwd while also having it sorted. To aid with user managment being able to look over a complet list of current users while creating new
users. Any and All assistance is greatly appriciated.
https://www.howtoforge.com/user_password_creating_with_a_bash_script 7/12
8/13/2018 Create Users And Change Passwords With A Bash Script
i not get clear what name to put for the bash file
I recommend you to create a file with username & password. Then the script will read the username and password from file and create user:
The file userlist.txt format:
username1 p@assword1
username2 p@assword2
..etc
The shell script:
#!/bin/bash
while read u1 p1
do
echo Username: $u1 Password: $p1 created
adduser $u1
echo $p1 | passwd --stdin "$u1"
echo Username: $u1 Password: $p1 created
done < userlist.txt
last, run the script as root:
sh createuser.sh
or:
chmode +x createuser.sh
./createuser.sh
https://www.howtoforge.com/user_password_creating_with_a_bash_script 8/12
8/13/2018 Create Users And Change Passwords With A Bash Script
dear,
I need to change database user passwd in mysql.
like as: i have db user name is openexchange and db name is oxdatabase_5, this database i have many user and passwd. i need to a bash script
which change user pass from oxdatabase_5 from http client interface.
i am using mail server for change their passwd.
Name:Address:Phone:Email
Name:Address:Phone:Email
How would I implement it in this code to adjust for that? I'm trying to learn and I'm not too familiar with what each command does!
This doesn't work when i run it, it will create new user but does not change the password
this is the error msg :-
passwd: Only one user name may be specified.
seems you need to modify below parameters. It should look like echo $i"123" | passwd "$i" --stdin
echo $i"123" | passwd –-stdin "$i"
https://www.howtoforge.com/user_password_creating_with_a_bash_script 9/12
8/13/2018 Create Users And Change Passwords With A Bash Script
Sign up now!
Tutorial Info
Author: fakrul
Tags: linux
40.2k Followers
https://www.howtoforge.com/user_password_creating_with_a_bash_script 10/12
8/13/2018 Create Users And Change Passwords With A Bash Script
Popular Tutorials
https://www.howtoforge.com/user_password_creating_with_a_bash_script 11/12
8/13/2018 Create Users And Change Passwords With A Bash Script
Xenforo skin by Xenfocus Contribute Contact Help Imprint and Legal Notice Tutorials Top
https://www.howtoforge.com/user_password_creating_with_a_bash_script 12/12