Sunday, September 23, 2012

Display current time in the prompt

UNIX Display current time in the prompt:
----------------------------------------------
In the PS1 environment variable, you can directly execute any Linux command, by specifying in the format $(linux_command). In the following example, the command "date" is executed to display the current time inside the prompt.

devaraj#export PS1="\u@\h [\$(date +%H:%M:%S)]# "
devaraj@my-serv [14:12:35]#
devaraj@my-serv [14:12:35]# date
Sun Sep 23 14:12:37 IST 2012

What Is a Kernel

What Is a Kernel?
--------------------

Let's start by providing a definition for the term kernel. The UNIX kernel is the software that manages the user program's access to the systems hardware and software resources. These resources range from being granted CPU time, accessing memory, reading and writing to the disk drives, connecting to the network, and interacting with the terminal or GUI interface. The kernel makes this all possible by controlling and providing access to memory, processor, input/output devices, disk files, and special services to user programs.

Kernel Services:
------------------

The basic UNIX kernel can be broken into four main subsystems:

Process Management
Memory Management
I/O Management
File Management

These subsystems should be viewed as separate entities that work in concert to provide services to a program that enable it to do meaningful work. These management subsystems make it possible for a user to access a database via a Web interface, print a report, or do something as complex as managing a 911 emergency system. At any moment in the system, numerous programs may request services from these subsystems. It is the kernel's responsibility to schedule work and, if the process is authorized, grant access to utilize these subsystems. In short, programs interact with the subsystems via software libraries and the systems call interface. Refer to your UNIX reference manuals for descriptions of the systems calls and libraries supported by your system. Because each of the subsystems is key to enabling a process to perform a useful function, we will cover the basics of each subsystem. We'll start by looking at how the UNIX kernel comes to life by way of the system initialization process.

Saturday, September 22, 2012

commands

du -adk . | sort -nr 

find command

Separate filenames using the null character:
--------------------------------------------------

find . -name "*.foo" | xargs grep bar

in practice does the same as

grep bar `find . -name "*.foo"`

but will work even if there are so many files to search that they will not all fit on a single command line. It searches in all files in the current directory and its subdirectories which end in .foo f
or occurrences of the string bar.

find . -name "*.foo" -print0 | xargs -0 grep bar

does the same thing, but uses GNU specific extensions to find and xargs to separate filenames using the null character; this will work even if there are whitespace characters, including newlines, 

Zombie process

What is Zombie process in UNIX? How do you find Zombie process in UNIX?

When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls 'wait()'; In the interval between the child terminating and the parent calling 'wait()', the child is said to be a 'zombie' (If you do 'ps', the child will have a 'Z' in its status field to indicate this.)

Zombie : The process is dead but have not been removed from the process table.

UNIX Single-User Mode:

UNIX Single-User Mode:
--------------------------
This mode can be reached through the automatic reboot sequence, or by the user booting with the -s option or setting the boot_single variable in loader.

It can also be reached by calling shutdown(8) without the reboot (-r) or halt (-h) options, from multi-user mode.

If the system console is set to insecure in /etc/ttys, then the system prompts for the root password before initiating single-user mode.

Example 13-3. An Insecure Console in /etc/ttys

# name getty type status comments
#
# If console is marked "insecure", then init will ask for the root password
# when going to single-user mode.
console none unknown off insecure

Note: An insecure console means that you consider your physical security to the console to be insecure, and want to make sure only someone who knows the root password may use single-user mode, and it does not mean that you want to run your console insecurely. Thus, if you want security, choose insecure, not secure.

Linux boot sequence

Booting the Linux operating system:
----------------------------------------

The first thing a computer does on start-up is a primer test (POST - Power On Self Test). This way several devices are tested, including the processor, memory, graphics card and the keyboard. Here is tested the boot medium (hard disk, floppy unit, CD-ROMs). After POST, the loader from a ROM loads the boot sector, which in turn loads the operating system from the active partition.
The boot blocks is always at the same place: track 0, cylinder 0, head 0 of the device from which we're booting. This block contains a program called loader, which in Linux's case is LiLo (Linux Loader), or Grub (GNU Grub Unified Boot Loader), which actually boots the operating system. These loaders in Linux , in case of a multi-boot configuration (more operating systems on a computer), permit the selection of the operating system to be booted. Lilo and Grub are installed or at the MBR (Master Boot Record), or at the first sector of the active partition.
In the following we will refer to LiLO as boot loader. This is usually installed in the boot sector, also known as MBR. If the user decides to boot Linux, LiLo will try to load the kernel. Now I will present step-by-step LiLo's attempt to load the operating system.

1. In case of a multi-boot config, LiLo permits the user two choose an operating system from the menu. The LiLo settings are stored at /etc/lilo.conf. System administrators use this file for a very detailed finement of the loader. Here can be manually set what operating systems are installed, as well as the method for loading any of them. If on the computer there is only Linux, LiLo can be set to load directly the kernel, and skip the selection menu.

2. The Linux kernel is compressed, and contains a small bit, which will decompress it. Immediately after the first step begins the decompression and the loading of the kernel.

3. If the kernel detects that your graphics card supports more complex text modes, Linux allows the usage of them - this can be specified or during the recompilation of the kernel, or right inside Lilo, or other program, like rdev.

4. The kernel verifies hardware configuration (floppy drive, hard disk, network adapters, etc) and configures the drivers for the system. During this operation, several informative messages are shown to the user.

5. The kernel tries to mount the file system and the system files. The location of system files is configurable during recompilation, or with other programs - LiLo and rdev. The file system type is automatically detected. The most used file systems on Linux are ext2 and ext3. If the mount fails, a so-called kernel panic will occur, and the system will "freeze".
System files are usually mounted in read-only mode, to permit a verification of them during the mount. This verification isn't indicated if the files were mounted in read-write mode.

6. After these steps, the kernel will start init, which will become process number 1, and will start the rest of the system.

Wednesday, August 10, 2011

Redirect website and access using mobile and PC

I have a website called

www.website.org

I have a mobile website called

m.website.org

I want to use an htaccess to automatically redirect the main website URL to the mobile version..

However, there is a link on the mobile version that points back to the main website called

www.website.org?noredirect=true

When I click the logo on the home page of the actual website it links to

www.website.org

I don't want the user to be allowed back to mobile accidentally by clicking on the logo on the main page. How can I accomplish this via htaccess without JavaSCript.

If not I am open-minded to alternate options.

EDIT

I think I am currently going to use this for sensing mobile redirect via htaccess

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|opera\ m(ob|in)i|palm(\ os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows\ (ce|phone)|xda|xiino [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a\ wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r\ |s\ )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1\ u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp(\ i|ip)|hs\-c|ht(c(\-|\ |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac(\ |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(\ |\/)|klon|kpt\ |kwc\-|kyo(c|k)|le(no|xi)|lg(\ g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-|\ |o|v)|zz)|mt(50|p1|v\ )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v\ )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-|\ )|webc|whit|wi(g\ |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-) [NC]
RewriteRule ^$ http://m.website.com [R,L]


URL: http://stackoverflow.com/questions/3680463/mobile-redirect-using-htaccess

Wednesday, January 26, 2011

Hard link and soft link

What is the difference between Hard Link and Soft Link in Linux?

Hard Link is a mirror copy of the original file. Hard links share the same inode.
Any changes made to the original or Hard linked file will reflect the other.
Even if you delete any one of the files, nothing will happen to the other.
Hard links can't cross file systems.

Soft Link is a symbolic link to the original file. Soft Links will have a different Inode value.
A soft link points to the original file. If you delete the original file, the soft link fails. If you delete the soft link, nothing will happen.
Hard links can cross file systems.




Lets learn the differnce with an example

Example: Create a file " original-file.txt "

:~/test$ echo "Learning about Hard and Soft Link" > original-file.txt
:~/test$ cat original-file.txt
Learning about Hard and Soft Link



Now lets create a Hard Link

Example: HardLink-file.txt

:~/test$ ln original-file.txt HardLink-file.txt
:~/test$ ls -il
total 8
840388 -rw-r--r-- 2 telson telson 33 2009-05-18 09:16 HardLink-file.txt
840388 -rw-r--r-- 2 telson telson 33 2009-05-18 09:16 original-file.txt



Now lets create a Soft Link

Example: SoftLink-file.txt

:~/test$ ln -s original-file.txt SoftLink-file.txt
:~/test$ ls -il
total 8
840388 -rw-r--r-- 2 telson telson 33 2009-05-18 09:16 HardLink-file.txt
840388 -rw-r--r-- 2 telson telson 33 2009-05-18 09:16 original-file.txt
840186 lrwxrwxrwx 1 telson telson 17 2009-05-18 09:23 SoftLink-file.txt -> original-file.txt



From the above ls -il result, you find the same inode for " HardLink-file.txt " and " original-file.txt ".
Inode value is different for the soft link " SoftLink-file.txt ".

Now lets try editing the original file:

Example:

:~/test$ cat >> original-file.txt
Editing this file to learn more!!

:~/test$ cat original-file.txt
Learning about Hard and Soft Link
Editing this file to learn more!!

:~/test$ cat HardLink-file.txt
Learning about Hard and Soft Link
Editing this file to learn more!!

:~/test$ cat SoftLink-file.txt
Learning about Hard and Soft Link
Editing this file to learn more!!

Now lets try changing the permissions:

Example:

:~/test$ chmod 700 original-file.txt
:~/test$ ls -il
total 8
840388 -rwx------ 2 telson telson 67 2009-05-18 09:34 HardLink-file.txt
840388 -rwx------ 2 telson telson 67 2009-05-18 09:34 original-file.txt
840186 lrwxrwxrwx 1 telson telson 17 2009-05-18 09:23 SoftLink-file.txt -> original-file.txt

From the above example its clear that changing the permission of " original-file.txt " will update the permission set of " HardLink-file.txt ".
The soft link remains unchanged.

Now lets try deleting the original file.

Example:

:~/test$ rm original-file.txt
:~/test$ ls -il
total 4
840388 -rwx------ 1 telson telson 67 2009-05-18 09:34 HardLink-file.txt
840186 lrwxrwxrwx 1 telson telson 17 2009-05-18 09:23 SoftLink-file.txt -> original-file.txt

:~/test$ cat HardLink-file.txt
Learning about Hard and Soft Link
Editing this file to learn more!!

:~/test$ cat SoftLink-file.txt
cat: SoftLink-file.txt: No such file or directory

So removing the original file will affect the Soft link. The Soft link fails.
Hard link is unaffected.

Monday, November 22, 2010

Sample form mail

$to = "testsimp@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "test@example";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>

Tuesday, November 16, 2010

SWftools installation

SWftools installation
=====================

http://www.swftools.org/download.html

web browser execution commands
==============================
pdftoswf.php
shell_exec('/usr/local/bin/pdf2swf -l -z -t TPT_poster.pdf -o TPT_poster.swf');
echo "Successfully converted";
?>


Testscript to pdf navigation
============================

$test=shell_exec('/usr/local/bin/pdf2swf -B /usr/local/src/swftools-0.9.1/swfs/rfxview.swf -l -z -t /home/user/public_html/dev/files/Test_File.pdf -o /home/tuser/public_html/dev/files/Test_File.swf ');
if($test) print_r($test);
echo "Conversion has been completed successfully";
?>

#/usr/local/src/swftools-0.9.1/swfs/rfxview.swf

?>





play="true" align="" loop="true" quality="high"
TYPE="application/x-shockwave-flash"
PLUGINSPAGE="[[http://www.macromedia.com/go/getflashplayer]]">

Tuesday, November 2, 2010

Port scanning script

#!/bin/bash
PORT1=21 #The port number
PORT2=22 #The port number
PORT3=25 #The port number
PORT4=53 #The port number
PORT5=80 #The port number
PORT6=3306 #The port number
read -p "Enter the Server IP/HOSTNAME : " HOSTNAME #Enter the Host Name to check the Open Ports
echo ""
echo "Checking the ping status of $HOSTNAME", Please wait....
echo ""
if ping -c2 $HOSTNAME |grep -i "time="
then
echo $HOSTNAME is up
else
echo "$HOSTNAME is down or unable to ping"
fi
echo ""
echo "Checking the port status of $HOSTNAME", Please wait....
echo ""
if nmap -p$PORT1 $HOSTNAME | grep -q open
then
echo $PORT1 is open
else
echo $PORT1 is down
fi
if nmap -p$PORT2 $HOSTNAME | grep -q open
then
echo $PORT2 is open
else
echo $PORT2 is down
fi
if nmap -p$PORT3 $HOSTNAME | grep -q open
then
echo $PORT3 is open
else
echo $PORT3 is down
fi
if nmap -p$PORT4 $HOSTNAME | grep -q open
then
echo $PORT4 is open

Thursday, September 30, 2010

How can I reset my admin password on my Plesk Linux server?

Follow the steps as follows


This can be accomplished with the ch_admin_passwd binary.


[root@plesklinux root]# cd /usr/local/psa/admin/bin/

[root@plesklinux bin]# ./ch_admin_passwd --help

./ch_admin_passwd: Utility to set Plesk adminstrator's password

Gets password from the environment variable PSA_PASSWORD

Password should be from 5 to 16 symbols and should not contain login name,

whitespace, quotes or national characters



Usage: ./ch_admin_passwd



-h, --help

display this help and exit



We must export the variable before running the binary. We will unset the variable when we are done.


[root@plesklinux bin]# export PSA_PASSWORD='newpass'

[root@plesklinux bin]# echo $PSA_PASSWORD

newpass

[root@plesklinux bin]# ./ch_admin_passwd

[root@plesklinux bin]# export PSA_PASSWORD=

[root@plesklinux bin]# cat /etc/psa/.psa.shadow

newpass

[root@plesklinux bin]#

Saturday, September 4, 2010

RED5 links

http://www.red5server.org/content_red5installlinux_500006
http://www.sohailriaz.com/how-to-install-red5-server-on-centos-53/
http://www.videochat-scripts.com/installed-red5-08-rc3-with-jdk-1613-on-linux/
http://forums.hostv.com/how-tos/71-how-install-red5-hosting-red5.html
http://gnufreakz.wordpress.com/2009/04/30/red5-installation/
http://hosting-marketers.com/news/category/red5-installation/
http://forums.hostv.com/how-tos/134-how-automated-red5-installation.html

Thursday, August 12, 2010

Linux tips and tricks

1.) To get Hardware info in GUI mode by using special package.

yum install hardinfo(system profiler and Beenchmark

2.)Non-GUI mode

dmidcoder | less

Gives you the information of whole hardware.

If you want know about hardware property

dmidcoder -t which prompts you the keyword for search

Videos tutorials

1.) How to setup load balance for apache.

http://www.youtube.com/watch?v=-WuW27hpHWc&feature=related

2.)Control and manage swap partion

http://www.youtube.com/watch?v=1q_05tD2gzY&feature=related

3.)Root password Hacking

http://www.youtube.com/watch?v=nT8X3d2nUrs&feature=related

Wednesday, August 11, 2010

MYSQL Downgrade / Upgrade

MYSQL Downgrade / Upgrade
=========================

Steps
-----

1. Check the mysql version

rpm -qa | grep -i mysql

mysql -v

2. Change the version in configuration file

Before changing th version in config file, backup the same
(cp -arp /var/cpanel/cpanel.config /var/cpanel/cpanel.config.bak)

In /var/cpanel/cpanel.config

Check for the line

mysql-version= 4.1

Change the version as you wish for upgrade or downgrade

Upgrade

mysql-version= 5.0

Downgrade

mysql-version= 4.0

Note: cPanel version 11.24.5-STABLE_38506 supports only mysql versions 4.1 and above

( How to check cPanel Version

/usr/local/cpanel/cpanel version or

vi /usr/local/cpanel/version )

3. Back up the /var/lib/mysql folder

( cp -arp /var/lib/mysql /var/lib/mysql_back )

4. Run the below script using below command

/script/mysqlup -force or
/script/mysqlup -force --password=ROOTPASSWORD

5. check the version of mysql
( rpm -qa | grep -i mysql

mysql -v)

6. /etc/init.d/mysql restart


If the mysql successfully restarts then there is no problem. But if it shows the errors

1. MySQL is not running, but lock exists
2. MySQL PID file could not be found!
3. MYSQL Cannot start because PID file not FOUND

Check the following

/etc/init.d/mysql status

"mysql is not running but lock exists "

Solved by removing the lock file:

rm /var/lock/subsys/mysql

If this happens again it may also be necessary to remove the pid file from /var/lib/mysql

Saturday, August 7, 2010

Preventing nobody spammer in PHP

PHP and Apache has a history of not being able to track which users are sending out mail through the PHP mail function from the nobody user causing leaks in formmail scripts and malicious users to spam from your server without you knowing who or where.

Watching your exim_mainlog doesn’t exactly help, you see th email going out but you can’t track from which user or script is sending it. This is a quick and dirty way to get around the nobody spam problem on your Linux server.

If you check out your PHP.ini file you’ll notice that your mail program is set to: /usr/sbin/sendmail and 99.99% of PHP scripts will just use the built in mail(); function for PHP – so everything will go through /usr/sbin/sendmail =)

Requirements:
We assume you’re using Apache 1.3x, PHP 4.3x and Exim. This may work on other systems but we’re only tested it on a Cpanel/WHM Red Hat Enterprise system.

Time:
10 Minutes, Root access required.

Step 1)
Login to your server and su – to root.

Step 2)
Turn off exim while we do this so it doesn’t freak out.
/etc/init.d/exim stop

Step 3)
Backup your original /usr/sbin/sendmail file. On systems using Exim MTA, the sendmail file is just basically a pointer to Exim itself.
mv /usr/sbin/sendmail /usr/sbin/sendmail.hidden

Step 4)
Create the spam monitoring script for the new sendmail.
pico /usr/sbin/sendmail

Paste in the following:

#!/usr/local/bin/perl

# use strict;
use Env;
my $date = `date`;
chomp $date;
open (INFO, “>>/var/log/spam_log”) || die “Failed to open file ::$!”;
my $uid = $>;
my @info = getpwuid($uid);
if($REMOTE_ADDR) {
print INFO “$date – $REMOTE_ADDR ran $SCRIPT_NAME at $SERVER_NAME n”;
}
else {

print INFO “$date – $PWD – @infon”;

}
my $mailprog = ‘/usr/sbin/sendmail.hidden’;
foreach (@ARGV) {
$arg=”$arg” . ” $_”;
}

open (MAIL,”|$mailprog $arg”) || die “cannot open $mailprog: $!n”;
while ( ) {
print MAIL;
}
close (INFO);
close (MAIL);

Step 5)
Change the new sendmail permissions
chmod +x /usr/sbin/sendmail

Step 6)
Create a new log file to keep a history of all mail going out of the server using web scripts
touch /var/log/spam_log

chmod 0777 /var/log/spam_log

Step 7)
Start Exim up again.
/etc/init.d/exim start

Step 8) Monitor your spam_log file for spam, try using any formmail or script that uses a mail function – a message board, a contact script.
tail – f /var/log/spam_log

Sample Log Output

Mon Apr 11 07:12:21 EDT 2005 – /home/username/public_html/directory/subdirectory – nobody x 99 99 Nobody / /sbin/nologin

Log Rotation Details
Your spam_log file isn’t set to be rotated so it might get to be very large quickly. Keep an eye on it and consider adding it to your logrotation.

pico /etc/logrotate.conf

FIND:
# no packages own wtmp — we’ll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}

ADD BELOW:

# SPAM LOG rotation
/var/log/spam_log {
monthly
create 0777 root root
rotate 1
}

Notes:
You may also want to chattr + i /usr/sbin/sendmail so it doesn’t get overwritten.

Enjoy knowing you can see nobody is actually somebody =)

Thursday, August 5, 2010

Useful links

1.) http://www.mysql-apache-php.com
2.)http://niyaas.blogspot.com
3.)http://shebangme.blogspot.com
4.)http://txt.binnyva.com
5.)http://gnufreakz.wordpress.com
6.)http://linuxserverguide.wordpress.com
7.)http://gcharriere.com/blog/?p=339 - Load balance
8.)www.howtoforge.com
9.)http://www.linuxbaby.co.cc
10.)http://www.dedicatedserverhosting.com
11.)http://www.linuxmaza.com
12.)http://scriptmantra.info
13.)http://skullboxx.net
14.)http://www.onetforum.com/fourm/viewtopic.php?p=27
15.)http://mohammednv.wordpress.com/2008/04/17/how-to-integrate-spamassassin-with-qmail/
16.)http://www.fduran.com/blog/filtering-spam-with-qmail-and-spamassassin-on-red-hat-fedora-2/
17.)http://www.onetforum.com/fourm/viewtopic.php?p=27
18.)http://www.wipl.in/articles/category/whm/
19.)http://wiki.cpaneldirect.net/wiki/index.php/Main_Page
20.)http://forums.cpanel.net/f5/problem-connecting-mysql-through-jailshell-109641.html
21.)http://articles.assistanz.com/?View=entry&EntryID=504
22.)http://www.comptechdoc.org/os/linux/usersguide/linux_ugprocesses.html
23.)http://www.linux.org/lessons/tips/cmndline.html
24.) http://marcgrabanski.com/articles/plesk-multiple-ftp-accounts-per-domain - FTP subaccount
25.)http://kmaiti.blogspot.com
26.)netstat -apn |grep :80 |awk {'print $5'} |wc -l
27.)http://tools.pingdom.com
28.)http://www.thecpaneladmin.com
29.)http://apache-monitor.com/articles/basic-apache-performance-tuning-httpd.php
30)http://supportfacility.com/blog/plesk/plesk-paths-on-a-linux-dedicated-server/
31.)http://www.howtoforge.org/set-up-dkim-for-multiple-domains-on-postfix-with-dkim-milter-2.8.x-centos-5.3

32.) http://www.thegeekstuff.com/2011/01/tput-command-examples/ - apache optimization steps

33.)http://linuxhostingsupport.net
34.)http://kmaiti.blogspot.com/
35.)http://www.xpcdesign.com/2010/03/plesk-commands-and-paths/
36.)http://www.linuxbabu.net/category/plesk/

Server security links
======================

http://abinz.wordpress.com/security-installations/
http://abinz.wordpress.com/security-installtion-phase-2/
http://abinz.wordpress.com/security-installation-phase3/
http://abinz.wordpress.com/securing-your-server/
http://abinz.wordpress.com/common-cpanel-issues/

http://sythril.com/showthread.php?t=9403 - VNC installation steps

http://www.eukhost.com/forums/f15/enable-php-mssql-extension-whm-cpanel-linux-server-10699/ ---mssql module installation

http://adminsdiary.com/linux/enable-php-mssql-extension-on-cpanel-linux-server - mssql moduler installation steps

Linux server secure steps

How to Secure Linux Servers
Basic Linux Server Security

Install Firewall (APF or CSF Firewall with BFD)
ModSecurity (Web application firewall)
ModEvasive (Prevent DDOS attacks)
Harden SSH server
Fix Open DNS Recursion
Install RKhunter
Install ClamAV (Antivirus)
XInet Servers Hardening (Disable Telnet/Finger or unwanted services)
Securing PHP
PortsEntry (tool to detect portscans)
Harden host.conf (against IP spoofing)
Check User Uploaded files
Secure /tmp Folders (noexec, nosuid)



This tutorial guide covers only basic linux server security tips intended for linux learners. I am writing this guide assuming that you are running Centos 5 or later versions.
Install Firewall

The very first first step on securing a server is installing a firewall (atleast IP tables based) to close all unused or unwanted ports. Once the firewall is installed it is often considered 50% of work done. You can install CSF firewall or APF firewall. Often BFD (brute force detection) utilities comes with firewall.

We will install CSF (Config security firewall) as it is easy to install with plenty of features and easily integrated to CPanel (if you are running)

wget http://www.configserver.com/free/csf.tgz
tar zxf csf.tar.gz
sh /csf/install.sh

Follow the installer and once installed, you can start the firewall.

csf -s
// start the firewall
csf -r
// restart the firewall
csf -f
// flush the rules or stop the firewall.

You can see the full installing tutorial here
Harden SSH server

Very often you will see SSH attacks from various bots trying to get access to your server by connected to port 22 with unlimited number of login attempts to break in to your system. Imagine attacks coming from different IPs can put lot of load in you server. You can trace those failed attempts by checking your log file

cat /var/log/secure
cat /var/log/messages

To harden your SSH server,

* Run SSH on other port rather than default port 22
* Disable Root login
* Use only protocol 2
* Enable Public key authentication.

You can see the full SSH hardening tutorial here
Disable Telnet & Other Unused Services

You may want to disable services like telnet, finger and other unwanted services running on your server with xinet.

nano /etc/xinetd.d/telnet
// OR
nano /etc/xinetd.d/krb5-telnet

look for lines disable=no and change to disable=yes

chkconfig telnet off
Hardening PHP for Security

PHP is the most popular scripting language for apache and mysql. You will need to disable system level functions in the php configuration file.

nano /usr/local/lib/php.ini

Look for the lines and make sure you have the lines as below..

disable_functions = exec,system,shell_exec,passthru
register_globals = Off
expose_php = Off
magic_quotes_gpc = On

It is best to keep magic_quotes to on as otherwise you forms using POST may be used for SQL injection attacks.
Disable Open DNS Recursion (DNS Server)

If you are running bind DNS server, then you might want to check your dns server statistics with dnstools.com. You dont want to allow recursive lookups to performed on your server other than local IP. It can also slowdown your server.

nano /etc/named.conf

Under Options { place a line

Options {
recursion no;
.....

Then restart the bind

service named restart

You will also need to restrict zone transfers and notifications if you are running Bind 9. Refer to: dns server hardening
Install Mod_Security

ModSecurity is a free open source web application firewall which can help you to guard against LFI (local file inclusion attacks) and SQL injection vulnerabilities.

CPanel Installation:

Just go to Cpanel WHM > Plugins > Enable Mod_Security > Save

Source Installation:

That should install mod security in your cpanel. Under apache it should show under installed modules if you run test.php with phpinfo() in it. Try adding some mod security rules. Installing mod_security could be sometimes complicated. Dont use apxs for compiling mod_security as it causes number of problems.

Note: Mod_security needs libxml2 and http-devel libraries before it can be installed. It also requires mod_unique_id enabled in apache modules. To install mod_unique_id, you have to place

LoadModule unique_id_module modules/mod_unique_id.so

in your httpd.conf file.

yum install libxml2 libxml2-devel httpd-devel

Download the latest version of mod_security for apache2 from http://www.modsecurity.org

wget http://www.modsecurity.org/download/modsecurity-apache_2.1.7.tar.gz
tar zxf modsecurity-apache_2.5.4.tar.gz
cd modsecurity-apache_2.5.4
cd apache2

Then

If you cannot find ./configure then you will need to edit Makefile and make change to top_dir = /usr/lib/httpd (for centos)

make
make install

Next, copy the rule files depending on which you want (you can also select minimal rules file which comes with source). Make a directory named modsecurity under /etc/httpd/conf and copy all the modsecurity rules there. Finally include those files in the httpd.conf file

# /etc/httpd/conf/httpd.conf

LoadModule unique_id_module modules/mod_unique_id.so
LoadFile /usr/lib/libxml2.so
LoadModule security2_module modules/mod_security2.so
Include conf/modsecurity/*.conf

Then

/etc/init.d/httpd restart

Log Files

Watch for log files to detect any errors or intrusion activity

/var/log/httpd/modsec_audit
/var/log/httpd/error_log

If you get any errors, i have compiled a list of errors while compiling. see here
Install Mod_Evasive

ModEvasive module for apache offers protection against DDOS (denial of service attacks) in your server.

wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
tar zxf mode_evasive-1.10.1.tar.gz
cd mod_evasive

then run the following command for apache2...

> /usr/sbin/apxs -cia mod_evasive20.c

Once mod evasive is installed, place the following lines in your /etc/httpd/conf/httpd.conf


DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10


Follow the instructions in the README for more tuning of mod_evasive. This will compile, install and activate the module in your server.
Install RkHunter (Rootkit)

RkHunter is a rootkit scanner scans for vulnerabilities, insecure files, backdoors in your system and reports it so that you can further harden the server. Installing RkHunter is very easy!

yum install rkhunter

To run checks in your system

rkhunter --checkall
OR
rkhunter -c

You can find what command options are available under rkhunter by issuing this help command

> rkhunter --help
Install PortsEntry

Portsentry is a tool to detect port scans and log it. Download the sorce package of portsentry from sourceforge.net

wget http://path/to/portsentry-1.2.tar.gz
tar zxf portsentry-1.2.tar.gz
make linux
make install

If you get errors like while compiling

make linux
SYSTYPE=linux
Making
gcc -O -Wall -DLINUX -DSUPPORT_STEALTH -o ./portsentry ./portsentry.c \
./portsentry_io.c ./portsentry_util.c
./portsentry.c: In function 'PortSentryModeTCP':
./portsentry.c:1187: warning: pointer targets in passing argument 3 of 'accept' differ in signedness
./portsentry.c: In function 'PortSentryModeUDP':
./portsentry.c:1384: warning: pointer targets in passing argument 6 of 'recvfrom' diffe r in signedness
./portsentry.c: In function 'Usage':
./portsentry.c:1584: error: missing terminating " character
./portsentry.c:1585: error: 'sourceforget' undeclared (first use in this function)
./portsentry.c:1585: error: (Each undeclared identifier is reported only once
./portsentry.c:1585: error: for each function it appears in.)
./portsentry.c:1585: error: expected ')' before 'dot'
./portsentry.c:1585: error: stray '\' in program
./portsentry.c:1585: error: missing terminating " character
./portsentry.c:1595: error: expected ';' before '}' token
make: *** [linux] Error 1

To fix:

Open portsentry.c and look for the following line. There will be a extra carriage return breaking the line and you have to delete the carriage return and make single line. It should look like below.

printf ("Copyright 1997-2003 Craig H. Rowland \n");

Then run make and make install. That should fix it!

To launch portsentry

/usr/local/psionic/portsentry/portsentry -stcp
/usr/local/psionic/portsentry/portsentry -sudp

check the log files /var/log/secure on what portsentry is active or not.
Prevent IP Spoofing

IP spoofing is a security exploit and can be prevented from placing nospoof on in host.conf file. Edit the host.conf file and place the following lines. If you run dns bind, give it preference.

order bind,hosts
nospoof on
Install ClamAV

Antivirus protection is the last thing you need for your security to protect against worms and trojans invading your mailbox and files! Just install clamav (a free open source antivirus software for linux). More information can be found on clamav website

yum install clamav

Once you have installed clamav in your centos…here are some of the basic commands using the software..

1. To update the antivirus database

> freshclam

2. To run antivirus

clamav -r /home

3. Running as Cron Daily Job

To run antivirus as a cron job (automatically scan daily) just run crontab -e from your command line. Then add the following line and save the file.

02 1 * * * root clamscan -R /var/www

This will run the cron job daily @ 1.02 AM by scanning the public html. You can change the folder to whatever you want for mail etc.

Thats it! Always keep an eye for log files for any attacks or error messages!

You can also post comments in my blog

Back to home