Tip: Add User and Generate Password Script

Hey guys!

Finally, I found time to update this lovely blog of mine. And luckily, I have one super cool simple script to share. This script will help a lot of system administrators in adding user accounts, very useful if you have about a hundred servers to login to and execute useradd and passwd again and again. This is a bash script, so no need to install packages and easy to understand.

Here goes the code.


#!/bin/bash

for USER in $(cat /tmp/users.txt) do
$(useradd $USER)
###Remove the space between 8 and )
PASSWORD=$(openssl rand -base64 8 )
###passwd [double dash] stdin
echo $PASSWORD | $(passwd –stdin $USER)
echo “$USER $PASSWORD” | mail -s “Your Account Info” $USER@company.com
sleep 3
done

Here is a quick summary of the code per line:

for USER in $(cat /tmp/users.txt) do
This line begins the for loop and /tmp/users.txt should be a text file containing the list of usernames to be added one username per line. The value of $USER

$(useradd $USER)
This line will begin by executing the command useradd. If the script fails at this point because the username already exists, it will proceed with changing the password of the username.

###Remove the space between 8 and )
###passwd [double dash] stdin
PASSWORD=$(openssl rand -base64 8 )
echo $PASSWORD | $(passwd --stdin $USER)

This line generates an 8-byte random password using openssl and pipes it to command passwd using –stdin option so the generated password can be passed.

echo “$USER $PASSWORD” | mail -s “Your Account Info” $USER@company.com
This line sends an email to the user containing the username and password, assuming that the email address is the same as the username.

This script can be further enhanced (imagination is limitless!) and feel free to share your script here.

Popularity: 5% [?]

Secure Files with Your IronKey

Working as a system administrator requires a lot of memory power with all the servers that I am managing at work. Not to say the huge amount of passwords that go with it. And I must admit that my memory is not to be trusted (hey, even Einstein once suggested not to trust your memory!) with these credentials that if compromised or forgotten, will mean death to my career.

Anyway, my boss from our California office gave me a little piece of technology that I carry around with me and though I have read it a few times before, I never got the chance to own one. I am talking about the IronKey, a military-grade secure flash drive that is designed to protect the stored files.

This drive claims to be the most secure drive in the world. It’s design lies in its hardware-based AES encryption that resists any attempt to bypass the password, and provides a tight security for the drive. It also protects your encrypted data from brute-force attacks by initiating a self-destruct process if the password is typed in incorrectly after the tenth try. Any attempts also to tamper the casing will trigger the drive to self-destruct the data, making sure that no one will get the data even if physically tampered.

The bundled software also provides the security needed to access the files by asking for a password to unlock the USB drive. Locked drive means no read-write access whatsoever. Secure backup is also provided so encrypted backups of the contents can be created without compromising the data.

All in all, IronKey is perfect for confidential files and should be the standard of all USB flash drives.

Popularity: 6% [?]

Tip: Testing Your PHP/MySQL Connection

How to test if PHP connects to MySQL database?

There are numerous times when I have to setup Apache and PHP on a freshly installed Linux server. Considering that not only that Apache service should work, I also have to make sure that PHP and MySQL are working properly together.

Forgetful that I am, I always tend to forget what components should I have to make PHP and MySQL talk to each other. You need something like a ’special glue’ to connect the two together and I will discuss here how to make PHP and MySQL work together for both RPM and source installation.
Read the rest of this entry »

Popularity: 14% [?]

Linux Tip: Reset Root Password

How to reset root password?

If you are as forgetful as I am, you have probably forgotten what password you have set for root user. Today, I am going to teach you a little tip on how to reset the root password.
Read the rest of this entry »

Popularity: 18% [?]