Tuesday, January 29, 2008

Find Other Web Sites Hosted on a Web Server

Came across a amazing site

YouGetSignal.com - Find Other Web Sites Hosted on a Web Server

Blogged with Flock

CHROOT command

The chroot command changes the 'root' to another location. This command is used to create a sandbox for the users. Once a new root is declared via chroot, any reference that a user makes to '/' will resolve to the new directory.

This is a very good idea to restrict users working under the real root filesystem.

Eg:- chroot /home/sushanth

This command changes the root of my server to /home/sushanth.

This means

vi /test

will cause test file to open under /home/sushanth

Blogged with Flock

To determine if a new PCI or USB hardware has been added in the system

If my goal is to see if a PCI or USB piece of hardware has been detected, you may be able to use the following commands

lspci and lsusb commands

Cheers !

Blogged with Flock

Monday, January 28, 2008

Password protecting webpages

Our task is to control the access the particular website.

1. cd /etc/httpd/conf

2. vi httpd.conf

3. Change the line that says
AllowOverride None
to
AllowOverride AuthConfig

4. While doing the above changes on the httpd.conf file be sure not to change the first ocurance change the second ocurrance.

5. Before doing any changes take a backup of httpd.conf file

6. You should now identify the folders under your webserver you would like to protect.

7. On a Linux server the actual directory path would be
/var/www/html/test
So on the web browser it would be
http://www.test.com/test

8. Once you identify which directory you will have to protect then inside that directory create one file .htaccess

9. vi .htaccess
AuthName "Login to the website"
AuthType Basic
AuthUserFile /var/www/html/test/.htpasswd
Require user sushanth

10. Note that AuthName requires quotes and whatever is in the quotes will be displayed on the login window.

11. Also be sure to include the user login names of the people who want to access the web site, next to the Require user line. In the above example is added my name.

12. Now create .htpasswd file in the same folder, in my case under test.

13. cd /var/www/html/test

14. htpasswd -cmb .htpasswd sushanth test123

15. Note that you must use your own name and password (replace sushanth and test123) and that the option cmb does the following: First it forces Creating of a new .htpasswd file. Since this is your first time adding a user it is necessary. Next the m option forces encryption and b allows you to include the user name and password immediately. In my case I created a new .htpasswd file, then added the user sushanth and her password test123.

16. Restart the apache services

17. test the website
www.test.com/test

18. There may come a time when you need to delete users from the access. You can do this easily enough by again editing the .htaccess file and running a command to delete the user from the .htpasswd file.

19. First, edit the .htaccess file and remove the user you do not wish to allow access to and save the file.

20. Second, delete the user from the .htpasswd file by typing this command at the prompt: htpasswd D sushanth
The option D is for delete. It should prompt you that user sushanth was deleted.

Sunday, January 13, 2008

Redirecting Website Using Apache Web Server

There are many methods to redirect a website or a webpage to another domain.

I have explained 2 options.

1. Use Apache Module (mod_rewrite)

In the Httpd.conf file

RewriteEngine On
RewriteRule /.* http://www.newdomain.com/

2. Use Apache Module (mod_alias)

In the Httpd.conf file

^Redirect domain
Redirect / http://www.newdomain.com/

^Redirect page
Redirect /webpage.html http://www.newdomain.com/new_webpage.html/

Error: Unable To Eject, Last Error: Invalid Argument

Error: Unable To Eject, Last Error: Invalid Argument

When we get this error, this means some user is accessing the CD-Rom.

Type the following command

#fuser /dev/cdrom

This command will tell the administrator, the processes that have a open file or are otherwise accessing.

#fuser -uik /dev/cdrom

This command will show the Process ID and the use who owns it. This helps the administrator the interactively kill the process so as to eject the CD-ROM.

Creating A Boot Disk For RedHat Linux

"mkbootdisk" command in order to use this you only need to know the kernel version of the operating system to write to the floppy.
You can get the kernel version of the operating system by using "uname -r"

To create a boot disk for the Linux operating system

#mkbootdisk 2.4.20-80

or

#mkbootdisk 'uname -r'

The mkbootdisk command collects info from /etc/fstab and /boot/grub/grub.conf.

In order to work out the root filesystem any required kernel command line arguments and the drivers which will be needed to generate the ramdisk image.

One useful but this command is not widely used

#mkbootdisk --iso option, which make the bootable for CD-ROM image.

Adding New Hard Disk On Linux Box

Linux stores all the known disk partition in /proc/partitions file

The Entire hard disk is represented by a entry with minor number 0, the partitions on the drive are sequentially numbered after that.

We have added a new hard disk and it is represented as /dev/hdb

Partitioning the new disk :

The first steo after adding the new disk is to partition it in preparation of the adding a filesystem to it.

#fdisk /dev/hdb

Make the Hard Disk as primary partition

Enter all the default values

Once done type "p" and check for the details

Then to save the changes type "w"

To verify the new partition

#cat /proc/partitions

Putting the directory structure on the newly formatted hard disk

#mkfs -t ext3 /dev/hdb1

#mkdir /mnt/hdb

To automatically mount the partition

#vi /etc/fstab

/dev/hdb1 /mnt/hdb1 ext3 defaults 1 2

Mount the partition

#mount -a

Sunday, December 16, 2007

What is "Force User" in SAMBA ?

[uniqname]
comment = Unique comment
path = /path/to/the/stuff
public = no
writable = yes
printable = no
valid users = user1,user2,user3
force user = sushanth

The 'force user' directive means that at the point of connection the real
users identity is lost and the user now is 'sushanth'.

Tuesday, November 6, 2007

Configuring Disk Quota

To implement file quota we need to edit /etc/fstab file and add the usrquota and grpquota option to the partition for which you want to enable quotas

#vi /etc/fstab

/dev/VolGroup00/LogVol00 /ext3 defaults,usrquota,grpquota 11

save the file

Remount the filesystem

#mount -o remount

or if we have entered more than one filesystem in the fstab file then to remount all the filesystem

#mount -a remount

Run quotacheck command to check for an errors on the filesystem with quota check

#quotacheck -augmv

Syntax info are as follows:

a= perform quotacheck on all filesystems
m= the filesystem should not be mounted as read-only mode
u & g= tells to check for users and groups

Turn on the quota

#quotaon -augmv

Apply the quota for a particular user

#edquota -u sushanth

Apply quota for particular group

#edquota -r susgrp

Monday, November 5, 2007

Disk Space Management Using LVM

Before starting this task it is necessary to install the LVM package

Linux Kernel 2.4.x has the LVM inbuilt.

In this blog we will focus on how to create an LVM layout and then mount it under the home directory

My root partition is sda1 and sda2 is my swap

To start partitioning run fdisk on /dev/sda

#fdisk /dev/sda
Enter p to create a new primary partition , accept all the default values for the start and end cylinders.

The next step is to change the partition into LVM. This means that we need to change the disk system ID into 8e as a partition type.

The above mentioned task can be done using fdisk command

Now we will create a volume group.

Volume group is nothing but two or more physical volumes together form a volume group.To bring our disk under the volume group we will have to configure our physical volumes.

#pvcreate /dev/sda (this command will initialise the physical volume)

We will now create a volume group which uses this physical volume

# vgcreate home2 /dev/sda (home2 is the volume group)

In this manner we can have multiple physical volume under volume group home2

Now we have created the volume group, now we will create logical volumes. We can have many logical volumes under one volume group. Or we can use one complete logical group has one Logical volume.

#lvcreate -n downloads --size 1G home2

The above mentioned command will create a logical volume as download with 1GB space under volume group home2

-n is used to name the logical volume.

Before we can use the Logical Volume, we need to format it and then mount it.

We will create a directory under /mnt as mystuff.

Now we will format the logical volume (/dev/home2/download)

#mkfs ext3 /dev/home2/download

Once the formatting is over we will mount the logical volume on to the /mnt/mystuff

#mount /dev/home2/download /mnt/mystuff

To make a permanent entry

#vi /etc/fstab

/dev/home2/download /mnt/mystuff ext3 defaults 12

save the file

Mount NTFS partition on a Linux Machine from Command Prompt

Check the Kernel Version

#uname -r

Install the following rpm

#rpm -ivh kernel-ntfs.rpm

The rpm is available at www.linux-ntfs.org

#modprobe ntfs

Mount the NTFS partition

#mount -t ntfs /dev/hdb /mnt/ntfs

(create a directory ntfs under mnt directory)

Make the mount permanent by making an entry in the /etc/fstab

#vi /etc/fstab

/dev/hdb /mnt/ntfs ntfs defaults 00

save the file

Tuesday, October 30, 2007

NFS Configuration

We will configure NFS, whereby we will mount /test directory on the other machine

NFS Server Configuration:

Create a Directory which we need to Mount using NFS

#mkdir /test

Start the following services :

#service portmap start

#service nfs start

#service nfslock start

Edit the following file:

#vi /etc/exportfs

/test xxx.xxx.xxx.xxx(ro,sync,no_root_squash)

(xxx.xxx.xxx.xxx replace it with NFS client IP address)

save the file

#export -avr

NFS Client Configuration:

Start the following services

#service nfs start

#service nfslock start

#service portmap start

Create a directory:

#mkdir test1

#mount xxx.xxx.xxx.xxx:/test /test1

(xxx.xxx.xxx.xxx replace it with NFS server IP Address)

Squid Proxy Configuration

The SQUID is a Linux based utility that can be used to distribute internet to all the computers within the network

Squid configuration file : squid.conf

Location: /etc/squid

Edit the squid.conf file

#vi squid.conf

(Search for the default acl list and add the following)

acl mynetwork src xxx.xxx.xxx.xxxx / xxx.xxx.xxx.xxx (subnet)
acl mynetwork src xxx.xxx.xxx.xxx / xxx.xxx.xxx.xxx (for individual IP)

Then add acl (access control list) to the "http_access list" with the following line

http_access allow mynetwork

Default port is always 3128

You can comment this line and add any specific port we require

http_port 3128

Once the above mentioned changes has been done, save the file

Restart the squid service

#/etc/rc.d/init.d/squid restart

or we can use the following command

#squid -z

#squid

One the client system , just all the proxy IP address (Squid Server IP address) and port 3128 or any other port specified in squid.conf file

Sunday, October 21, 2007

Changing Kernel Parameters

To Display all the available Kernel Parameters

# sudo sysctl -a | sort | more

Each Kernel parameters are in a field = value format

For Example:

Kernel.threads-max = 16379

Decreasing the PID value will improve the performance

To change the parameter

# sudo sysctl -w kernel.threads-max=16000

The above command will change the parameter temporarily, once the machine reboots the parameters will come back to its previous value.

To make the new changes permanently , Edit the following

# /etc/sysctl.conf

Enter in the parameter changes

For example:

#vi /etc/sysctl.conf

kernel.threads-max=16000

save the file

Thursday, October 18, 2007

Change Linux Server date from GST to GMT

Edit the following :

# vi /etc/sysconfig/clock
Zone="GMT0"
UTC=true
ARC=false
:wq!

Delete file name localtime

#cd /etc

#rm -i localtime

Create a softlink

#ln -s /usr/share/zoneinfo/GMT0 /etc/localtime

Now check the date

Synchronise hardware clock with system clock

#hwclock --show

#hwclock --set --date="today's date time"

eg:

#hwclock --set --date="02/19/207 18:10:00"

#hwclock --show

#date

Synchronise hardware clock to system clock

#hwclock --hctosys

Wednesday, October 17, 2007

Compile and Install a New Linux Kernel

Download the latest kernel from www.kernel.org

#wget http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.4.19.tar.gz

#tar zxvf linux-2.4.19.tar.gz

#cd linux-2.4.19

Now you have to configure the kernel options
This is place where you select all the features you want to compile into the kernel. If you have an existing configuration from the older kernel, copy the old .config file to the top level of your source and use make oldconfig instead of menuconfig. This oldconfig process will carry over your previous settings and prompt you if, there are new features not covered by the earlier .config file.
We will presently follow a technique whereby we are just Compiling and Installing a new Kernel.

#make menuconfig

Now you will have to build all the dependencies for your chosen configuration.

#make dep

Now we can compile the actual Kernel

#make bzImage

The resulting kernel file is : arch/i386/boot/bzImage

Now you have to load the modules

#make modules

Install the modules

#make modules_install

Due to some reason you want to re-compile the whole kernel once again. You can use make command to delete intermediate file.
make mrproper command will delete he .config file

Task are as follows:

make mrproper
make menuconfig
make dep
make clean
make bzImage
make modules
make modules_install

Once the task is completed, now we have to boot from the new kernel. I take into consideration that LILO is installed in boot sector.

Before changing its better practice to take a backup

#cp arch/i386/boot/bzImage/vmlinuz-2.4.19

#cp system.map /boot

Now once the above mentioned steps are done we can tell the LILO about the new kernel

Edit the following lilo.conf file

#vi /etc/lilo.conf

image=/boot/vmlinuz-2.4.19
label="Linux 2.4.19"

:wq!

To apply the changes and boot from the new kernel

# lilo -v

Reboot the server.

Wednesday, October 10, 2007

Network Bonding Configuration

1. #/etc/sysconfig/network-scripts

2. create a file
# touch ifcfg-bond0

3. Edit the file
#vi ifcfg-bond0

4. Enter in the details
DEVICE=bond0
USERCTL=no
ONBOOT=yes
BROADCAST=xxx.xxx.xxx.xxx
NETWORK=xxx.xxx.xxx.xxx
NETMASK=xxx.xxx.xxx.xxx
GATEWAY=xxx.xxx.xxx.xxx
IPADDR=xxx.xxx.xxx.xxx

5. Edit ifcfg-eth0
#vi ifcfg-eth0

6. Enter in the details
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

7. Edit ifcfg-eth1
#vi ifcfg-eth1

8. Enter in the details
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

if the operating system is RHEL 32-bit then edit the following

1. #vi /etc/modules.conf
alias bond0 bonding
options bonding miimon=100 mode=0

if the operating system is RHEL 64-bit then edit the following

1. #vi /etc/modprobe.com
alias bond0 bonding
options bonding miimon=100 mode=0

Restart the network services

# service network restart