Monday, December 19, 2011

Password Protection to your Website Hosted on Apache Web Server

At times, when I am browsing the web, I click on a link such as this one and instead of a web page, I get a dialog box asking me to enter my user name and password. And only after I have been authenticated do I get access to the website (or page). This feature of password protection is very simple to implement in Apache web server.

Password authentication process contains two files:
1. .htpasswd :-
This file contains the user name - password combination of the users who are allowed access to the website or page. This file can reside anywhere in file system. But usually, it is created in the Apache web server directory ( /etc/httpd/conf/.htpasswd ). This is because, this file should not be accessible to the visitors of the site.

2. .htaccess :-
This file defines the actual rules based on which users are given access or denied access to the website. This file should reside in the base directory of one's website. For example, if my website is located in the path '/var/www/' and I want to provide user authentication to the entire website, then I will store the file .htaccess in the following location - '/var/www/rootuser/.htaccess '.

[ Note = Here iam using the configuration of apache web server which i have posted earlier ]

1] Create new users and share them access for website.
[root@server ~]# useradd anup
[root@server ~]# passwd anup

[root@server~]# useradd shubham
[root@server ~]# passwd shubham

2] Now create the .htpasswd file which contain the password of user to access web site.
[root@server ~]# htpasswd -cd /etc/httpd/conf/.htpasswd anup
New password:
Re-type new password:

[ Note = Here in above command -c used to Create a new file, -d Force CRYPT encryption of the password. Any number of users and their password may be entered in the same .htpasswd file per website.]

3] Create the .htaccess file which will prohibit the full website which is situated in /var/www/rootuser.
[root@server ~]# vim /var/www/rootuser/.htaccess
AuthUserFile /etc/httpd/conf/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require user anup shubham

[ Note = Here AuthUserFile is the location of .htpasswd file, AuthGroupFile to group file which contain the group of users. Here i don't have any group file hence it points to /dev/null, AuthName is Web site name, AuthType value is Basic that instructs apache to accept basic unencrypted password from remote user's web browser, require user this option tells the apache that only the user whith name anup & shubham have access.
4] Change permission of both file.
[root@server ~]# chmod 600 /etc/httpd/conf/.htpasswd
[root@server ~]# chmod 600 /var/www/html/rootuser/.htaccess

5] Make changes in apache main configuration file i.e. httpd.conf
[root@server ~]# vim /etc/httpd/conf/httpd.conf

<Directory /var/www/html/>
AllowOverride None

<Directory /var/www/rootuser/>
AllowOverride AuthConfig

6] Restart the apache web server
[root@server ~]# service httpd restart
** Now open the website from now any user who visit website will first have to enter username and password to access website.

Web Server Configuration

Apache HTTP Server is a webserver developed and maintained by The Apache Software Foundation. Apache is the most popular web server, used on more than half of all Internet web servers. Most Linux distributions include Apache. Apache's advantages include its modular design, SSL support, stability and speed. Given the appropriate hardware and configuration it can support the highest loads. On Linux systems, the server configuration is usually done in the /etc/httpd directory. The most important configuration file is httpd.conf.

  • Package = httpd
  • Service = httpd
  • Port No. = 80
  • Configuration File = /etc/httpd/conf/httpd.conf
Per quest:-
  • Configure IP =
  • Configure Virtual IP = &
  • Configure Hostname =
  • Firewall must be disabled
[ Note = Here on & on ]

1] Install required package for apache web server.
[root@server ~]# yum install http* -y

2] Edit the /etc/hosts file.
[root@server ~]# vi /etc/hosts [ Insert following lines at the end of file ] www www www

3] Restart the network service.
[root@server ~]# service network restart
[root@server ~]# chkconfig network on

4] Append the main configuration file.
[root@server ~]# vim /etc/httpd/conf/httpd.conf
# Insert following lines at the end of file
DocumentRoot /var/www/html/rootuser
DirectoryIndex index.html
DocumentRoot /var/www/html/anup
DirectoryIndex index.html
#Following site is port based.
Listen 500
DocumentRoot /var/www/html/shubham
DirectoryIndex index.html

5] Now create the resources for website
[root@server ~]# cd /var/www/html
[root@server html]# mkdir {rootuser,anup,shubham}
[root@server html]# cd rootuser
[root@server rootuser]# cat > index.html
<b bgcolor=pink>Welcome to</b>
[root@server rootuser]# cd .. | cd anup
[root@server anup]# cat > index.html
<b bgcolor=yellow>Welcome to</b>
[root@server anup]# cd .. | cd shubham
[root@server shubham]# cat > index.html
<b bgcolor=green>Welcome to</b>
[root@server shubham]# cd

6] Start the httpd service
[root@server ~]# service httpd start
[root@server ~]# chkconfig httpd on

*Point your browser to following URL:
> OR
> OR
> OR

[ If these website are opening without error then your Apache web server is working properly. ]

Saturday, December 03, 2011

DHCP Server Configuration

Dynamic Host Configuration Protocol (DHCP) automatically assigns IP addresses and other network configuration information (subnetmask, broadcast address, etc) to computers on a network. A client configured for DHCP will send out a broadcast request to the DHCP server requesting an address. The DHCP server will then issue a "lease" and assign it to that client. The time period of a valid lease can be specified on the server.
  • DHCP assignment:
    • Lease Request: Client broadcasts request to DHCP server with a source address of and a destination address of The request includes the MAC address which is used to direct the reply.
    • IP lease offer: DHCP server replies with an IP address, subnet mask, network gateway, name of the domain, name servers, duration of the lease and the IP address of the DHCP server.
    • Lease Selection: Client recieves offer and broadcasts to DHCP servers that will accept given offer so that other DHCP server need not make an offer.
    • The DHCP server then sends an ack to the client. The client is configured to use TCP/IP.
    • Lease Renewal: When half of the lease time has expired, the client will issue a new request to the DHCP server.
  • Package = dhcp
  • Service = dhcpd
  • Port No. = 67
  • Configuration File = /etc/dhcpd.conf
Per quest:-
  • Configure IP =
  • Configure Hostname =
  • Firewall must be disabled.
1] Install required package
[root@server ~]# yum install dhcp* -y

2] Copy the new sample file and paste it under /etc directory
[root@server ~]# cp /usr/share/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf

3] Edit the dhcpd.conf file as follows: ( Make changes which are denoted in BOLD format)
[root@rootuser ~]# vi /etc/dhcpd.conf
ddns-update-style interim;
ignore cient-updates;

subnet netmask {

option routers;
option subnet-mask;
options nis-domain “”;
option domain-name “”;
option domain-name-servers;

option time-offset -1800; # Eastern
# option ntp-servers;
# option netbios-name-servers;
# --- Selects point-to-point node ( default is hybrid )
# -- You understand Netbios very well
# option netbios-node-type 2;

range dynamic-bootp;
default-lease-time 21600;
max-lease-time 43200;
# we want to nameserver to appear at a fixed address
host client {
hardware ethernet 12:AH:CD:78:43:GI;

4] Crete one blank file to store allocated ip address to client
[root@server ~]# touch /var/lib/dhcpd/dhcp.ip

5] Start dhcp service
[root@server ~]# service dhcpd start
[root@server ~]# chkconfig dhcpd on

DHCP Client Side:-
1] Set the ip address to dynamic from LAN card properties
[client@server~]# setup
Select the Network configureation --> Select Edit Network Devices --> Select device eth0 --> Select option Use DHCP [ * ] --> Then Ok --> Quit --> Save&quit --> Quit

2] Restart network service
[root@server ~]# service network restart
[root@server ~]# chkconfig network on

3] Now check IP address for eth0 device
[root@server ~]# ifconfig eth0

NFS Server Configuration

NFS stands for Network File System. NFS protocol used for sharing files between computer network. NFS allowes to mount files on remote computer as well as on local computer. For NFS server the server machine and client machine both are must be Linux OS, NFS does not support Windows machine because Windows is not NFS compatible. The NFS server shares one or more directories to client system.

  • Package = nfs
  • Service = nfs
  • Port No. = 2049
  • Configuration File = /etc/exports
Per quest:-
  • Configure Server IP =
  • Configure Client IP =
  • Confiugre Server Hostname =
  • Configure Client Hostname =
  • Firewall must be disabled.
1] Install required package
[root@server ~]# yum install nfs* -y

2] Create one new directory to share it using NFS server
[root@server ~]# mkdir /data
[root@server~]# cd /data
[root@server data]# touch anup1 anup2 anup3 anup4 anup5
[root@server data]# cd

3] Grant full permissions to data directory.
[root@server ~]# chmod 777 /data

4] Open main configuration file i.e. /etc/exports and share /data directory to network
[root@server~]# vim /etc/exports
/data,sync) #Here rw means r for read & w for write
#You can allow data directory to specific IP als.
#You can insert entry for data directory by following way
/data *(rw,sync)
/data *(ro,sync)
/data,sync) #Share directory using Hostname
5] Now start NFS service
[root@server ~]# service nfs start
[root@server ~]# chkconfig nfs on

6] Update exports file entries
[root@server ~]# exportfs -r

NFS Client Side:-
1] Check communication with NFS Server
[root@client ~]# ping

2] Check NFS server exports list
[root@client ~]# showmount -e

3] Create mount point to mount shared directory
[root@client ~]# mkdir /testnfs

4] Now mount shared directory.
[root@client ~]# mount -t nfs /testnfs
[root@client ~]# cd /testnfs
[root@client testnfs]# ls
[root@client testnfs]# cat > testfile
This is test file from client.
[root@client testnfs]# cd

[ Note = In this way you can use shared directory. But this directory will be available till system is up, it will not availabe after system reboot. To keep it available after reboot use following way: ]
[root@client ~]# vim /etc/fstab (Go to end of the file and make following entry)      /testnfs      nfs      defaults     0 0
[root@client ~]# mount -a

[ Reboot computer using reboot command and check /testnfs directory]

Friday, December 02, 2011

Samba Server Configuration

Samba is a software suite that provides file and print sharing services to SMB/CIFS clients. Samba is freely available and it supports Linux/Unix and Windows clients. Samba allows other computer platforms, such as Mac OS, Unix, Linux, IBM System 390 with Windows computers on the same network. Samba includes sharing files and sharing devices such as printer connected to other computers within the local network.

  • Package = samba
  • Service = smb
  • Port No. = 445
  • Configuration File = /etc/samba/smb.conf
Per quest:-
  • Configure IP =
  • Hostname =
  • Firewall should be off on server.
1] Install required packages
[root@server ~]# yum install samba* -y

2] Create one new user
[root@server ~]# useradd anup
[root@server~]# passwd anup

3] Create new directory that will host Samba share and grant it full permission.
[root@server ~]# mkdir /mydata
[root@server ~]# chmod 777 mydata

4] Create some files under mydata directory
[root@server ~]# cd /mydata
[root@servermydata]# touch a1 n2 u3 p4
[root@server mydata]# cd

5] Now add anup user to Samba user
[root@server ~]# smbpasswd -a anup
New SMB password:
Retype new SMB password:

6] Use following command to confirm user was added to the samba database
[root@server ~]# pdbedit -w -L

7] Edit main configuration file
[root@server ~]# vim /etc/samba/smb.conf
#By default name of workgroup is MYGROUP you can change to desire name.
workgroup = rootuser
#Remove hash from follwing line and edit as follows
hosts allow
#Go to end of the file and type as follows:
comment = mysamba
path = /mydata #samba share directory name
public = no #Can not be used by pulic users
browseable = yes
valid users = anup #Only user anup can use samba share

8] Set Selinux security related options
[root@server ~]# chcon -t samba_shared_t /mydata

9] Use following command to check smb.conf file parameter
[root@server ~]# testparm

10] Start the smb service and make it permanent
[root@server~]# service smb start
[root@server ~]# chkconfig smb on

Client Side Configuration:-
1] Check communication with Samba server
[anup@server ~]$ ping

2] Create one directory to store downloaded files.
[anup@server~]$ mkdir /client

3] Now try to connect to Samba server
[anup@server ~]$ smbclient // -U anup
smb:\> ls
smb:\> get a1
smb:\> exit
4] You can also mount samba share directory
[anup@server ~]# smbmount /client -o username=anup

Windows client side configuration:-
1] Check communication with Samba server
cmd\> ping

2] Change computer name to windowsclient and change workgroup to rootuser
Right click on My Computer --> Select Properties --> Click the Computer Name Tab --> Select Change button --> Type the computer name in given filed and type the workgroup name in workgroup filed.

3] After reboot open Go to Start --> Select Search option --> then search Samba server with it's ip

Wednesday, November 30, 2011

LAMP Server Configuration

LAMP stand Linux (operating system) Apache (HTTP server) MySQL (database software) and PHP ( or Perl or Python). LAMP Server is Linux web development environment. It allowes you to create web applications with Apache, PHP and MySQL database. It also come with PHPMyAdmin and SQLiteManager to easily manage your database.

Per quest on server:-
  • Configure IP =
  • Hostname =
1] Install Apache
[root@server ~]# yum install httpd  -y

2] Start apache service
[root@server ~]# service httpd start
[root@server ~]# chkconfig httpd on

3] Install MySQL Database Server
[ MySQL is a widely used open source database server on most linux server and can very well integrate tp PHP and Apache server on RHEL5 ]
[root@server ~]# yum install mysql mysql-server -y
[root@server ~]# service mysqld start

4] Change MySQL root password [ By default the root password is empty for mysql database. ]
[root@server ~]# mysql
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('newpassword') WHERE user='root';

5] Once done check by loging in:
[root@server ~]# mysql -u root -p
Enter password: <your new password>

6] Create a new mysql user
[root@server ~]# mysql -u root -p
mysql> create database lamp
mysql> GRANT ALL PRIVILEGES ON lamp.* TO 'anup'@'localhost' IDENTIFIED BY 'anup' WITH GRANT OPTION;
mysql> UPDATE user SET Password=PASSWORD('anup') WHERE user='anup';
mysql> quit

7] Install PHP language
[root@server ~]# yum install php php-gd -y

8] To load PHP restart apache
[root@server ~]# service httpd restart

9] To test PHP working or not
[root@server ~]# vim /var/www/htm/demo.php
// demo.php

10] Open the browser and type following URL
Syntax = http://<ip address>/demo.php
  • Observe the installed configuration on server
    • PHP paths
    • Apache paths and loaded module
    • PHP gd library
    • MySQL path
11] Download and Install PHPMyAdmin
[ PHPMyAdmin is web based MySQL database administration tool ]

12] Edit phpmyadmin configuration file
[root@server ~]# vi /etc/httpd/conf.d/phpmyadmin.conf (Remove the hash from Deny from all)
<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
  # Deny from all
  Allow from
13] Open file and make following changes
[root@server ~]# vi /usr/share/phpmyadmin/
$cfg[ 'blowfish_secret' ] = 'password'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

14] Restart all service once again
[root@server ~]# service httpd restart
[root@server ~]# service mysqld restart
[root@server ~]# chkconfig httpd on
[root@server~]# chkconfig mysqld on

15] Ponit your browser to following URL:
Syntax = http://<ip address>/phpmyadmin

[ Note = If you encounter of error to open phpmyadmin then paste extracted directory of phpmyadmin to /var/www/html/ and rename it as phpmyadmin ]

Tuesday, November 29, 2011

YUM Configuration

YUM stands for Yellowdog Update Modifier. Yum is used to install package in network. Yum is configured on one server in network and client uses that the repo file to install package from server. Yum resolves the dependency problem.
  • Red hat installed machine
  • DVD/CD of Red Hat Enterprise Linux
Per quest:-
  • Configure IP =
  • Hostname =
1] Mount the CD/DVD
[root@server ~]# mount /dev/cdrom /mnt
2] Install required package
[root@server ~]# cd /mnt/Server
[root@server Server]# rpm -ivh vsftpd-2.0.5(press tab)
[root@server Server]# rpm -ivh createrepo(press tab)
3] Copy all the content of CD/DVD under pub directory which is automatically created when you install vsftpd package
[root@server ~]# cp -rvp /mnt/* /var/ftp/pub/
4] Now create repository of package to Serve directory
[root@server ~]# createrepo -g /var/ftp/pub/Server
5] Now create repo file which containthe path of yum server
[root@server ~]# vim /etc/yum.repos.d/anup.repo
name = my yum server
6] Set Selinux secrity related options.
[root@server ~]# getsebool -a | grep ftp
[root@server~]# setsebool allow_ftpd_full_access on
[root@server ~]# setsebool ftp_home_dir on
[root@server ~]# getsebool -a | grep ftp
7] Start the vsftpd server
[root@server ~]# service vsftpd start
[root@server ~]# chkconfig vsftpd on
8] Now update the yum
[root@server ~]# yum clean all
[root@server ~]# yum update all
9] To test Yum Server install any package the dependency problem is must be resolved by Yum.
[root@server ~]# yum install firefox* -y
YUM Client Side:-
1] Check communication with server
[anup@client ~]$ ping
2] Now create the repo file which contain the path of yum server
[anup@client ~]$ vim /etc/yum.repos.d/client.repo
name=my yum server
3] Finall update yum
[anup@client ~]$ yum clean all
[anup@client ~]$ yum update all
4] Try to install package
[anup@client ~]$ yum install firefox* -y
5] To remove package
[anup@client ~]$ yum remove firefox* -y