• Home
  • Portfolio
  • Store
  • Book
  • Contact Us
  • Download
  • All About Linux
Knowledge is priceless!

but will be useless unless it shared…

  • Photography
  • Linux/*BSD/*NIX
  • Photoshop
  • PHP/MySQL
  • Joy & Sorrow
  • Cisco
  • MS Windows
  • Security Matter
  • etc
Jan
9

Using Bash Script to Mass Create Users And Change Passwords

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



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

Save the file as adduser.sh and exit.

chmod 755 adduser.sh

Now run the file:

./adduser.sh

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.

Create another bash file as follows:

#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i"123" | passwd –-stdin "$i"
echo; echo "Password for user $i has been changed!"
done

Run the file. All the passwords are changed.

If you want to force all your users to change password, use the following code:

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 | chage -d 0 "$i"
echo; echo "User $i will be forced to change password on next login!"
done

I then log as that user and see this

WARNING: Your password has expired.
You must change your password now and login again!
Changing password for user amcorona.
Changing password for amcorona
(current) UNIX password:

Source: http://www.linewbie.com/

Buy me a cup of coffee to help me keep posting here, I'm sleepy...

Tags: change user, faq, howto, id, Linux, login, mass, passwd

Posted by Adi Sunardy, RHCT Linux/*BSD/*NIX Subscribe to RSS feed

Leave a Reply

Click here to cancel reply.

You must be logged in to post a comment.

Links

  • Avudz
  • Bustanul Jannah
  • Domain Seller
  • E-Book Online
  • Forum Elektro Unsyiah
  • Hubbul Walidainy
  • My Book Store
  • My Portfolio
  • My Store
  • Psychiatrist Online
  • Travelling Guidance
  • Yudhi Aswad
Your Ad Here



Site Build It!

Recent Posts

  • Use Multilink PPP to combine multiple circuits into a single circuit with a single router interface
  • Using an Old Cingular SIM in the iPhone and Made it Work
  • Using Nepenthes Honeypots to Detect Common Malware
  • Simple Cumulative Math Using Awk On Unix or Linux
  • Photo shooting checklist for panoramas
  • How to shoot photos for great looking panoramas
  • Installing Windows 7 Beta
  • Selecting & Extracting Hair – Masking Tutorial – Extraction Tips
  • Digital Nip Tuck
  • Creating a Secure PHP Login Script

Tags

    3700 3700 series add user aperture backup Blog bracketing BSD change hostname Change the Color of an Eye change user Cisco digital eye enhancement eyes faq fedora howto id Joy & Sorrow Linux Linux/*BSD/*NIX login managing group Managing User mass MySQL new site passwd password Photography Photoshop PHP rancid reboot red hat reset router Script solaris teeth Unix Using The Red Eye Tool Non-Destructively video youtube

Online Advertising


Powered by:




RSS
Copyright © 2010 Knowledge is priceless! All rights reserved. Blue Grace theme by Vladimir Prelovac.