Upgrading OpenSSL

This one works for me on upgrading openssl.

1. Check your openssl version

# openssl version

OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

2. Download latest version of openssl

http://www.openssl.org/source/

or you may command

wget http://www.openssl.org/source/openssl-1.0.0d.tar.gz

3. Extract openssl-1.0.0d.tar.gz

Go to openssl-1.0.0d directory

# make clean
# ./config shared –prefix=/usr –openssldir=/usr/local/openssl
# make && make test
# make install

4. Done

5. Check the if you you have the latest version

# openssl version

OpenSSL 1.0.0d 8 Feb 2011

Enjoy….. ^__^

Delete user and directory

This script check the user if available if yes will prompt to delete the user and the directory.

#***********************************************************************

#!/bin/bash
#Script by Jeffrey Dante

#Check User if available

if [ $(id -u) -eq 0 ]; then
echo “Checking user $1″
cat /etc/passwd | awk -F: ‘{print $1}’ | grep -w $1
if [ $? -eq 0 ]; then

#Check User Disk Usage
LETTER=`/bin/echo $1 | /bin/awk ‘BEGIN{FS=””}{print $1}’`
DU=/usr/bin/du
echo “Disk Usage:”
$DU -msh /mnt/emaildata/$LETTER/$1/Maildir | awk ‘{print $1}’

while true;
do
read -p “Do you wish to delete this user $1 ? ”  yn
case $yn in
[Yy]* ) userdel $1; rm -r /mnt/emaildata/$LETTER/$1; echo “User $1 has been deleted”; exit;;
[Nn]* ) exit;;
* ) echo “Please answer yes or no.”;;
esac
done

exit 1

else
echo “$1 does not exists!”
fi

else
echo “Only root may delete a user”
exit 2
fi

#***********************************************************************

Script to add user and alias

I have seen similar script like this, I just added some arguments to make it suffice.

#**************************************************************************

#!/bin/bash
# Script to add a user with password and alias
# Jeffrey Dante

ADDUSER=/usr/sbin/adduser

if [ $(id -u) -eq 0 ]; then
read -p “Enter username : ” username
read -p “Enter email address: ” email
read -s -p “Enter password : ” password
egrep “^$username” /etc/passwd >/dev/null
egrep “^$email” /etc/aliases >/dev/null
if [ $? -eq 0 ]; then
echo “$username already exists!”
echo “$email already exist!”
echo “Make it sure that you do not have desame username and emaill address!”
exit 1
else
pass=$(perl -e ‘print crypt($ARGV[0], “password”)’ $password)
$ADDUSER -s /sbin/nologin -m -p $pass $username -G 100 $1
echo -e “$email:\t$username” >> /etc/aliases
echo -e “$email” >> /usr/files/addresses.txt
[ $? -eq 0 ] && echo “User has been added to system!” || echo “Failed to add a user!”

fi
else
echo “Only root may add a user to the system”
exit 2
fi
#**************************************************************************

Check User Script

I have created check user script to list the username, email alias, and the disk usage of the user. I hope this will give you some ideas preparing your own check user script.

#***********************************************************************
#!/bin/bash
#Script by Jeffrey Dante
#Check User if available
#List the email alias
#Show the directory usage

if [ $(id -u) -eq 0 ]; then
cat /etc/passwd | awk -F: ‘{print $1}’ | grep -w $1
if [ $? -eq 0 ]; then

# email: username
cat /etc/aliases | grep -w $1 | awk -F: ‘{print $1}’

# Check User Disk Usage

LETTER=`/bin/echo $1 | /bin/awk ‘BEGIN{FS=””}{print $1}’`
DU=/usr/bin/du
echo “Disk Usage:”
$DU -msh /mnt/emaildata/$LETTER/$1/Maildir | awk ‘{print $1}’

exit 1

else
echo “$1 does not exists!”
fi

else
echo “User verification Done!”
exit 2
fi

#***********************************************************************

Output should look like this
user
email/s
usage

[root@test.com jedscripts]# ./usercheck.sh jepdante
jepdante
jeffrey.dante@test.com
jeffrey_dante@test.com
Disk Usage:
55M

Installing openssl

To install openssl you can just do

yum install openssl

Or to update or do it manually:

1. check version
[root@test ]# openssl version
OpenSSL 0.9.7a Feb 19 2003

or

[root@test ]# openssl
OpenSSL> version
OpenSSL 0.9.7a Feb 19 2003

2. download latest openssl
3. extract

tar -zxvf openssl-1.0.0d.tar.gz

4. go to directory

cd openssl-1.0.0d

5. configure

./config shared –prefix=/usr –openssldir=/usr/local/openssl
make && make test
make install

6. if ask perl 5

yum install perl-DBI

Grep & Tar Linux Command for email on selected user

A. GREP

To grep the email by year and ouput its total email

ls –full-time | grep “2010\\-” | wc -l

To grep the email by year and month. ex 2010-01

ls –full-time | grep “2010\\-01\\-”

To grep the email by year, month and date. ex 2010-01-22

ls –full-time | grep “2010\\-01\\-22”

To grep the email by year, month, date and hour. ex 2010-01-22 10am

ls –full-time | grep “2010\\-01\\-22\\ 10”


B. TAR – backup

To Tar it with extension of .tar.gz

tar -cvzf 2010-04-27-18h.tar.gz `ls –full-time | grep “2010\\-04\\-27\\ 18” | awk ‘{print $9}’`
C. Untar

To Untar it, just go to the directory you want to extract it.

tar -xvf 2010-04-27-18h.tar.gz

ClamAV Installation

1. Download latest package
# useradd -s /sbin/nologin -c “Clam AV” clamav
# tar -zxvf clamav-0.96.3.tar.gz
# cd clamav-0.96.3
# ./configure
note: install package needed first and do ./configure again
yum install gcc-c++
yum install zlib-devel
# make && make install

2. Edit config file located at /usr/local/etc (clamd.conf and freshclam.conf)
for clamd.conf
# vi /usr/local/etc/clamd.conf
comment # example
comment # LocalSocket /tmp/clamd
comment # FixStaleSocket
uncomment TCPSocket 3310

for freshclam.conf
# vi /usr/local/etc/freshclam.conf
comment # example

3. Run freshclam to update virus definition files
# freshclam

NOTE: copy the init file for automatic start in bootup

# /usr/local/sbin/clamd -c /usr/local/etc/clamd.conf

4. # cp clamd /etc/init.d/clamd
note: —–-script to start clamd

# chmod u+x /etc/init.d/clamd
note: —–executable

BACKUP USING RSYNC & SSH With no password (FEDORA 15)

This one helps me a lot easier backing up the files from one server to backup server without password prompt.

Thanks to Lubos Rendek on his post at http://linuxconfig.org/Passwordless_ssh you make my life easier hahahah.

Follow the steps below
1. Generate ssh key on Local Server

[admin@localserver .ssh]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/admin/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/admin/.ssh/id_rsa.
Your public key has been saved in /home/admin/.ssh/id_rsa.pub.
The key fingerprint is:
12:d7:c2:24:18:07:ac:49:25:34:d0:f1:ed:e5:5a:6e admin@localserver
The key’s randomart image is:
+–[ RSA 2048]—-+
|.+=+++o .        |
|  o+oo + .       |
| . o. o = .      |
|  o  . = .       |
|      o S        |
|       =         |
|      . E        |
|       .         |
|                 |
+—————–+

2. Check the file if properly generated

[admin@localserver .ssh]$ ls -la
total 20
drwx——.  2 admin admin 4096 Aug 19 11:40 .
drwx——. 32 admin admin 4096 Aug 19 11:37 ..
-rw——-.  1 admin admin 1679 Aug 19 11:40 id_rsa
-rw-r–r–.  1 admin admin  400 Aug 19 11:40 id_rsa.pub
-rw-r–r–.  1 admin admin 2740 Aug 18 14:52 known_hosts

3. Copy ssh id to Backup Server

[admin@localserver .ssh]$ ssh-copy-id admin@backupserver
admin@backupserver’s password:
Now try logging into the machine, with “ssh ‘admin@backupserver'”, and check in:

~/.ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.

4. Login to Backup Server

[admin@localserver .ssh]$ ssh admin@backupserver
Last login: Thu Aug 18 17:22:33 2011 from 192.168.1.7
[admin@backupserver~]$ logout
Connection to backupserver closed.
[admin@localserver .ssh]$

5. Create Backup Script

[admin@localserver Downloads]$ vi new-rsync.sh

#!/bin/bash
RSYNC=/usr/bin/rsync
$RSYNC -ave ssh /home/admin/Downloads/temp admin@backupserver:/home/admin/Documents

6. Save the script (:wq!)
chown 755 new-rsync.sh

7. Test the script

[admin@localserver Downloads]$ ./new-rsync.sh
sending incremental file list

sent 87 bytes  received 13 bytes  66.67 bytes/sec
total size is 5309440  speedup is 53094.40

8. Create Cronjob

crontab -e

add

# BACKUP
00 00 * * * /home/admin/Downloads/new-rsync.sh

Done!