Archive for the ‘ Tips ’ Category

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: 15% [?]

Tip: Can Download Torrents But Cannot Browse

I have recently purchased a new home office router that connects two desktops and one laptop by wireless connection. Back at the store, I made my mind to purchase Linksys WRT54G over D-Link (I forgot the model) because there are a lot of good feedbacks on Linksys.

Everything was good the first two weeks we were using the router. The signal strength is good and my laptop can get decent W-Fi signal anywhere inside. Then the network became rather choppy, pings are intermittent, and worst, one desktop (particularly my desktop PC) cannot browse.

The weird thing I was able to download stuff using torrent, my Pidgin can sign in to my accounts on Yahoo and MSN Messenger and streaming video and music works. Everything works, except for the browser. I blamed the Linksys for this and contacted the support thrice, and I was given a lot of configurations that should be done in the router settings, none of which solved my problem.

Googling around got me some help and apparently, this weird symptoms are caused by the traffic from torrent downloads. To fix this, these settings must be done on the torrent client:

1. Reduce the download and upload speed of torrent client. Since I use the lightweight uTorrent Client, I can simply do this by right-clicking the uTorrent taskbar and selecting the download speed that I want. The procedure could be different depending on your client.

2. Disable DHT. DHT stands for Distributed Hash Tables and disabling this in torrent client effectively solved my problem with browsing. Again in uTorrent, this can be done by pressing CTRL+P to open the Preferences window and selecting the BitTorrent tab. Uncheck the DHT selections and click OK to save the new settings. Restarting the client helps too.

I did these two steps and this solved the issue of not being able to browse the Internet while downloading torrents.

Popularity: 7% [?]

Tip: Hiding Files Inside An Image in Linux

I have a previous post on how to hide files inside an image file in Windows. If you have not read or watched the video yet, it is right here.

Anyway, a comment on that post gave a tip on how to do the same thing on Linux. Of course I tried it and it worked! According to Sebastian of mathemaniac.org, the concept here is really simple. An image file like JPG is read from the beginning of the file and terminated with an ‘End of Image’ marker. An archive file like ZIP has their metadata stored at the end of the file. Put them together and the image will be read as a valid image file and the appended ZIP file will be read as an archive.

Here is how to do it in Linux:

Get an image file and an archive of the files that you want to hide. In this example, I have cat beer_and_cig.jpg and hideme.zip file. The zip file contains an MP3 song that I have stored inside the archive. To create the archive-image file, run this command:

cat beer_and_cig.jpg hideme.zip > ucantseeme.jpg

What this does is the ‘cat‘ command reads the image file first, then reads the zip file and puts them together in the file named ucantseeme.jpg.

To test the integrity of the image file, try this:

# unzip -t ucantseeme.jpg
Archive: ucantseeme.jpg
warning [ucantseeme.jpg]: 4751 extra bytes at beginning or within zipfile
(attempting to process anyway)
testing: Feist - 09 - One Two Three Four.mp3 OK
No errors detected in compressed data of ucantseeme.jpg.

Notice the warning message? The test saw that there were few bytes at the beginning, which means it saw the image file first but the archive is intact and no errors were found.

Perfect!

Popularity: 100% [?]

Tip: How Change Default OS in Dual Boot Ubuntu

My Acer 5570 Notebook is setup to dual boot Windows XP, for my online games and other Windows applications, and Kubuntu 7.10, my main operating system for stuff that I do most of the time like web browsing and blogging. Then my brother and I are now sharing the same notebook and he prefers Windows over Linux, not that I refuse to introduce him to Ubuntu but he had to use Microsoft Office for his office documents.

Windows and Ubuntu dual-boot systems are set boot Ubuntu first by default, so I decided to change the dual-boot order to default to Windows, since my brother will be using the notebook more.

To make Windows the default operating system in dual boot Ubuntu, follow these steps:

1. Press Alt+F2 to open the run dialog box.
2. Type in sudo gedit /boot/grub/menu.lst. Type in root password.
3. Edit the line that looks like this:

default 0

Change the number to the equivalent order of Windows in the operating system list in GRUB boot screen. The number 0 means that GRUB will boot the first operating system, and so on. If Windows is in the 4th line, change the number to 3.

4. Save the file and exit.
5. Reboot to check the change.

Windows should boot as default.

Popularity: 20% [?]

Tip: Perl script to Check Site Availability

System Administrators’s ‘common tasks’ are usually monitoring numbers of servers and network connections, and doing each monitoring is rather tedious. So to make our jobs and lives easier, we write scripts to automate repetitive tasks.

Since this is my Linux blog anyway, I decided to share one of scripts that I use in the office. This one is the Perl script that I use to check a specific site if the keyword is present, hence confirming that the site is up and accessible. Read the rest of this entry »

Popularity: 11% [?]

Tip: Simple SSL Certificate Scanner

If ever you need to write a script that needs you to scan the details of an SSL Certificate of a particular website, you can use this nifty one-liner to get the information that you need.

Security Certificates identify your site as a legit site and offers more secure connection by encrypting the data as it passes along the Internet highway. If the data is encrypted, chances are, the data being transmitted is less likely to be sniffed by malicious hackers.

If you manage hundreds of websites, each with its own SSL certificate that expires on different dates, you will need to create a script that will scan the certificates and capture the expiration dates and there is a nifty Linux command that can do this. Read the rest of this entry »

Popularity: 10% [?]

Tip: How to Schedule Tasks

If you are using Windows, you are probably familiar with task scheduler to schedule certain tasks automatically. With Linux, tasks can be done on scheduled dates with cron.

cron is the service that works like task scheduler in Windows and can be used if you want to automate repetitive tasks like generating reports everyday or virus scanning. cron is handled by the cron daemon or crond, which should be running if you want your scheduled tasks to run.
Read the rest of this entry »

Popularity: 5% [?]

Hacker’s Black Book

Being a systems administrator, it my job to deter mischievous users who plans to cyber-attack any of our servers and boy, it is easier said than done. Hackers are always a step ahead and a vulnerability will attract malicious hackers into your innocent server like ants to sugar. And so I purchased a book that will help me understand a little more about hacking.
Read the rest of this entry »

Popularity: 5% [?]

Stop Identity Theft Now

Since the beginning of Internet, securing personal privacy is always prioritized. Information is always available when we need it but other people also has access to the same information. Then comes identity theft.
Read the rest of this entry »

Popularity: 11% [?]

Tip: How to Delete Files with Special Characters

How to delete files with dash or any special character?

Have you tried to delete a who-knows-where-it-came-from file which has a special character like preceded with dash or question mark? I bet that when you tried to delete it, you got something like this:
Read the rest of this entry »

Popularity: 9% [?]