Thursday, May 14, 2015

APT-Advanced Package Tool

APT
APT -  Advanced Package Tool is a command line application tool to handle the installation and removal of software on the Debian based distribution and its variants. APT simplifies the process of managing software on Unix-like computer systems by automating the retrieval, configuration and installation of software packages, either from precompiled files or by compiling source code.

It handles the retrieval, configuration and installation of software packages.
Automatic dependency checking and resolution.
Relies on repositories which are central “stores” of available packages.
Has a myriad of front-ends such as aptitude, Synaptic, Adept.


Repositories
4 Components
Whether or not it supports Free Software Philosophy
- Main – Free software that gets security updates and its fully supported.
- Restricted – Not completely free & partially supported.
- Universe – Snapshot of FOSS world with most any application you can find in the open source world. Variety of licenses.
- Multiverse – Not free and not supported.

Apt examples
Note: root is disabled by default so sudo allows you to run commands with superuser privileges

# apt-get install packagename – installs software package
# apt-get remove packagename – removes package'
# apt-get update – updates list of software packages.
# apt-get upgrade – installs upgrades of all packages currently installed.
# apt-get dist-upgrade – upgrades to latest release


Apt for AMP

Install Apache, Php and MySQL
# apt-get install apache2 php5-mysql libapache2-mod-php5 mysql-server

Now, you can Configure and deploy securely.



MCELOG - hardware error log monitoring tool on x86 systems


mcelog logs hardware related errors on Linux based x86 systems. Mostly this tool is used on physical server and start at boot time (used to be at cron) and runs as a daemon. it can detech hardware error such as system bus errors, CPU error (cache error on processor or hardware) and most importantly memory error (Error Correction code-ECC). Once it detech the error threshold, it can predictively offline memory pages and CPUs  based on the error. If you check the error frequently, you will find the problem before server panic and crash.


Install mcelog
# yum install mcelog

Verify the daemon is running
# mcelog --client
# /etc/init.d/mcelog status
#  service mcelogd status

Dependencies
- Make sure  /dev/mcelog does exists. If not create with mknod command
# mknod /dev/mcelog c 10 227



How to find the error?
- Login to console and run the meclog command which read message from the kernel. Make sure to send output to a file because you can't re-run it see the error.
# /usr/sbin/mcelog >/var/tmp/mymce.log

Check the log
# more /var/log/mcelog
# grep -i "hardware error" /var/log/mcelog
# more /var/log/mcelog
# tail -200 /var/log/mcelog

Put it on cron,
[ $(grep -c "hardware error" /var/log/mcelog) -gt 0 ] && echo "Hardware Error on $(hostname)" | mailx -s "Error on `hostname`" sam@domain.com




Most of the systems are by default set up to dump the log at /var/log/mcelog.

Some commands
mcelog
mcelog --k8
mcelog --k8 --ascii
mcelog --k8 /dev/mcelog
mcelog --ascii /dev/mcelog
mcelog --ascii > changelog.txt
dmesg | grep ADMA
dmesg | grep ata5
vmstat -d


Note: If mcelog running as a daemon, you get the /dev/mcelog output when the MCE actually happens..

More on http://www.mcelog.org/

By analyzing the log, it appears that the server suffered a crash and dump file is generated which infact caused the /var/crash to fill up. It appears that the crash dump also caused the memory errors on the system.

Friday, May 8, 2015

Find changed files on the system



The command below List all files along with md5 information from your system.
# find / -type f | xargs md5sum > All_Files-`date +%m%d%y`

Note: May take long time to complete.

The command below List all files along with md5 information that are changed within last 5 minutes.
# find / -type f -mmin -5 | xargs md5sum > Changed_Files-`date +%m%d%y`

To find the difference between old record and new one, run the diff command

# diff All_Files Changed_Files


You can script the task as follow
# for((i=1;i<=16;i++)) do find ~/ -type f > new;diff original new; done



Compiling kernel from scratch

Download the latest patch and sources from kernel.org.

http://www.kernel.org/pub/linux/kernel.../linux-2....tar.bz2
http://www.kernel.org/pub/linux/kernel.../patch-2.....bz2

unzip the file and apply the patch:
# tar xvf linux-2.6....bz2
# mv patch-2......bz2 linux-2..../
# cd linux-2....

How to generate a crash dump on Redhat

How to generate a crash dump on Redhat

1. Install following Packages
# rpm -qa | grep -i dump # kdump must be installed.
# yum install kexec-tools crash kernel-debuginfo kernel-debuginfo-common system-config-kdump

2. Edit the /boot/grub/grub.conf
on the kernel line on /boot/grub/grub.conf file, append crashkernel=512M@256M

kernel /vmlinuz-2.6.32-504.1.3.el6.x86_64 .....  crashkernel=512M@256M

or

If you are on GUI
Run the command system-config-kdumpIn and on target settings tab, select the appropriate path and the partition value
Click apply and reboot the system.

3. Modify the config file /etc/kdump.conf to specify the dump location.

# more /etc/kdump.conf
path /opt/crash
core_collector makedumpfile -c --message-level 1 -d 31
default reboot

4. Restart the kdump service
# chkconfig kdump on
# service kdump stop/start
It will create new kdump boot image..

5. Reboot the server
# reboot

6. Core will be generated but may take time to complete.

Locate the core
# echo c > /proc/sysrq-trigger

7. Analyze the core
# ls /var/crash
# ls -l /opt/crash/127.0.0.1-2015-05-08-09\:24\:46/vmcore
# crash ls -l /opt/crash/127.0.0.1-2015-05-08-09\:24\:46/vmcore /usr/lib/debug/lib/modules/`uname -r`/vmlinux

Available Commands:
crash> help
crash> sys
crash> bt -a
crash> mod
crash> log

do man crash for more info..
crash> sys

Thursday, May 7, 2015

How to Reverse the Order of PDF Pages

How to Reverse the Order of PDF Pages
I just scanned the document but the first page become last and last page become first. Here is the instruction to change the page order. 

Req: Download and install Cutepdf

1. Open your pdf document with Adobe Acrobat
2. Now press CTRL+P which opens the printing dialog box.
3. On the page to print section, click on reverse pages. [ you may have to click on more option ]
4. Now, undr printer section, select CutePDF and ok to save it..


This should bring your last page to the top & continue until all pages have been reverse ordered.

Wednesday, May 6, 2015

password policy

password policy

A. password complexity

# more /etc/pam.d/system-auth

- Set Minimum Password Length to 10
- Enforce not to repeat already used password.
# grep pam_cracklib.so /etc/pam.d/system-auth
password    requisite     pam_cracklib.so try_first_pass retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1 difok=3

# grep pam_unix.so /etc/pam.d/system-auth
password   sufficient   pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=5

"remember=5" - will stores old password on /etc/security/opasswd.

B. Set Password Expiration date

# grep PASS /etc/login.defs

# Get account age information
# chage -l user1

-> Set account password expiration date
# chage -E 12/30/2015 -m 5 -M 90 -I 30 -W 14 jsmith

-E = Expired date [ or YYYY-MM-DD ], if set -E = -1, account will not expire.
-m = minimum number of days between password changes. 0 mean password can be change any time.
-M = maximum number of days a password is valid
-I = number of days of inactivity after a password has expired before the account is locked
-W = number of days of warning before a password change is required