Wednesday, 10 April 2013

How to limit bandwidth using yum when downloading or updating package from Online repository

Open yum.conf file
#vim /etc/yum.conf
#add the following line
throttle=50k
It will limit the speed 50KB/S while installing the package from the online repo using yum

How to create Password protected website on Apache in Centos 6

                                                                     
                                                                     
                                                                     
                                             
######### Creating a Passowrd Protected Website #################
1. Create your default website and check its working on browswer
When the website is working

2. Create a htpasswd file in /etc/httpd/conf/
[root@dhcppc9 conf]# htpasswd -c .htpasswd mind
New password: 
Re-type new password: 
Adding password for user mind

3. Set .htpasswd file permission 0644 so that it is accessed to apache user and group of apache server.
chmod 0644 .htpasswd 

4. Now create .htaccess file in your document root where the website is placed (/var/www/html/site1)
#vim /var/www/html/site1/.htaccess
Now paste the following lines in this file
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /etc/httpd/conf/.htpasswd                 -- path of htpasswd file
require valid-user
5. set permission 0644 to this file so that it is access to apache user and group.
[root@dhcppc9 conf]# chmod 0644 /var/www/html/site1/.htaccess 

6. Now open httpd.conf file and paste the following lines in your virutal host 
<Directory "/var/www/html/site1">  --- path of your document root
  AllowOverride AuthConfig
  # The Options below is an example. Use what you deem is necessary.
  Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
  Order allow,deny
  Allow from all
</Directory>

7. Service httpd restart



How to create vi editor colourfull

Step1. login as root on terminal
Step 2. vim /root/bashrc
step 3. Add the following line   
 
alias vi=vim
Now restart the terminal

How to create Yum Server Using ftp or vsftp

############## Yum Server Through FTP #############################
1. Install vsftpd (Very Secure ftp) Package.
2. Service vsftpd restart ( Main Demn ftp).
3. chkconfig vsftpd on
Main ftp directory /var/ftp/pub. Create directory under pub lets say centos.
Now copy all the rpm in this directory.
#cp -var * /var/ftp/pub/centos
4. Install createrepo
[root@mail Packages]# yum install createrepo
5.[root@mail Packages]# yum clean all
6. [root@mail Packages]# createrepo /var/ftp/pub/centos/
7. Now create .repo for local and for client
[root@mail Packages]# cd /etc/yum.repos.d/
[root@mail yum.repos.d]# touch ftp.repo
[root@mail yum.repos.d]# vim ftp.repo
copy and paster following ftp.repo
#-- repo id
[ftp]
# -- name of repo
Name = ftp repo
# - path of repo
baseurl = file///var/ftp/pub/centos
-- disable = 0, enabled = 1
enabled = 1
#gpg file path
gpgcheck = 0

### Client side adding repo ###
create the following .repo file
[ftp]
Name = ftp repo
baseurl = ftp://172.16.3.108/pub/centos
enabled = 1
gpgcheck = 0

This type of ftp created is anonymous ftp which means anybody can access the ftp server.

############## Securing ftp with username & password #######################
# Create a ftp user with password
1. # useradd ftp
 2. # passwd ftp
# deny ssh access to ftp user
 3. #usermod -s /sbin/nologin test  
# Now create a file chroot_list and add ftp user entery into this
4. #vim /etc/vsftpd/chroot_list
Note : make ftp sure user entery should not be in these two files "ftpusers", "user_list" which is under localtion /etc/vsftpd. If ftp user entery exists remove it.
# Making changes in main config file vsftpd.conf for user access
[root@mail vsftpd]# vim /etc/vsftpd/vsftpd.conf
Line 
No
12 anonymous_enable=NO
39 xferlog_enable=YES (log file)
# Line no 82 means log will be created in two files. One is xferlog.log, second is vsftpd.log which is under location /var/log
 82 dual_log_enable=YES
# Line no 83 means files will not be downloaded from the ftp server.Only user can upload the files.
 83 download_enable=NO
 85 ftpd_banner=Welcome to FTP Server made by Vijay Kumar
 97 chroot_list_enable=YES
 99 chroot_list_file=/etc/vsftpd/chroot_list
:wq

https://security.appspot.com/vsftpd/vsftpd_conf.html

Tuesday, 9 April 2013

Linux Shell Script for checking Network connectivity

Here is the sample script to find out which host is up and which one is down

#!/bin/bash
#Author: Vijay Kumar
#Date: 10.04.2013
#Purpose: Write a shell script to check network status

for (( i=1; i <=50; i++))
do
ping 192.168.1.$i -c 1 -i 3 &>/dev/null

if [ $? -eq 0]
then
echo "Host 192.168.1.$i is up"
else
echo "Host 192.168.1.$i is down"
fi
done

#END