Tuesday, August 2, 2011

Setup Password protect file via shell

1. Create a file name .htaccess in the folder that you want to password protect with the content below.

AuthType Basic
AuthUserFile /home/username/pass
AuthName "Members Area"
require valid-user

2. In shell, type

/usr/local/apache/bin/htpasswd -c /home/username/pass your_desire_username

You will be prompt for a new password.

3. Enter the password and confirm it.

Once you enter your password, file with name .htpasswd will be created at /home/username directory and now the website folder has been password protected.

4. To add additional users,

/usr/local/apache/bin/htpasswd /home/username/pass your_desire_username

5. To remove users edit /home/username/pass and remove the line contains the username.

More information: http://blog.dreamhosters.com/kbase/index.cgi?area=834

A memory testing tool

cd /usr/local/src

wget http://pyropus.ca/software/memtester/memtester-4.0.5.tar.gz

tar -zxf memtester-4.0.5.tar.gz

cd memtester-4.0.5

make

./memtester 1024 5 for 1gb(1024 mb) RAM .



The test will be run 5 times.

To list only directories

If you want to list only directories you can use this.

ls -d */.

cut command

I have a large text file (its a log file actually) and I need to truncate each line to about 16 characters.

cut -c1-16 /path/to/filename > /path/to/output_filename

output_filename will contain the result.

Some useful sed commands

to remove the first line of a file from our output stream

$ sed -e '1d' filename | more

to delete lines 1-10 of the output

$ sed -e '1,10d' filename | more

to delete lines that start with a "#" from files

$ sed -e '/^#/d' filename | more

to print only virtualHosts in apache conf

$ sed -n '/^ /path/to/httpd.conf

Tuesday, July 26, 2011

Delete a file using Inode number

You can delete a file using it's inode number as follows.
find . -inum 88 -exec rm -i {} \;

This will find the file with inum 88 in the present directory and delete it.

Kernel Compilation

Kernel Compilation
KERNEL DOWNLOAD: Download the latest one
http://www.kernel.org/pub/linux/kernel/v2.6/
linux-2.6.20.tar.bz2
tar jxf linux-2.6.20.tar.bz2
http://www.linuxelectrons.com/News/HowTO/20040315152255759

for i in `lsmod | awk {'print $1'}`; do find /lib/modules/2.4.27-grsec/kernel/ -iname ${i}.o ; done | wc
lsmod | wc

for i in `lsmod | awk {'print $1'}`; do find /lib/modules/2.4.28-grsec/kernel/ -iname ${i}.o ; done |wc

In 2.6 kernel
for i in `lsmod | awk {'print $1'}`; do find /lib/modules/2.6.20/kernel/ -iname ${i}.ko ; done


cd /usr/src/linux-2.6.24
make clean
make mrproper
make menuconfig

in general tab
==> Processor Type and Features
==> High Memory support
==> select 64 bit
go to general
==> Power management
==> Disable Cpu Scaling
go to general
==> Networking
==> Networking option
==> network packet filtering framework -> netfilter
==> enable network packet filtering debugging
==> core net filtering
==> select all as modules
come back
==> IP net filter
==> select All
go to general
==> Decice Drivers
==> Serail ATA LibATA or Serial ATA Parallel ATA
==> Select all INTEL as modules
==> select libata
==> Select Intel ESB|IDH|PIIX3|PATA
go to genral
==> FileSystem
==> make sure ext2/ext3 enabled
go back to general
==> Quota support On

make
make modules_install
make install

To boot once with the currently compiled kernel use below. Further reboots will be done on the existing kernel.

echo "savedefault --default=2 --once" | grub --batch
reboot

Remember to replace "2" to match your own config!