Friday, 2 November 2012

File Permissions

File Permissions

Working with files and directories in linux is difficult if you don't know about the file permissions of the linux system. In this post, we will learn about the file permissions and advanced file permissions.

There are three types of file permissions:


To see the, if the directory contains which of the items, we use the command:

# ls directory_name

also to see the file permissions, we use :

# ls -l directory_name

For example:

drwxrwxr-x 3 john john 4096 Oct 20 17:00 Music/

In this case, d stands for directory r stands for Read permission w stands for write permission and x stands for execute permission.

Here three rwx stands for three persons:

first for user, second for group and third for others.

User is one who is John in above example, group is also john, and the permission is applied on directory Music .

The main command for changing the file permissions in redhat is:

# chmod 777 filename

Here permission is 777 in which first 7 for user second 7 for group and last 7 for others.

Now what is the meaning of 7.

At the beginning of the post I write:


for read, 4 for write 2 , for execute 1

means if we want to give full permissions add all the three. 4+2+1=7

If don't want to give write permission then


Similarly different combinations can be made as.

# chmod 751 filename

In this way, we can customize the permissions.

Also, there is another useful permission known as FACL.


Using this tool we can assign special permission to a single user. We can allow or deny users for accessing particular items.

This tool can be used using command:

# getfacl filename

This command shows the special permissions on filename.

To apply permissions, we can use following command:

# setfacl -m u:username:rwx filename

#setfacl -m u:username:r-- filename

To remove these permissions use command:

# setfacl -x u:username:rwx filename

For more information, use mannuals using man command.

Wednesday, 31 October 2012

Apache Server

Apache Server

Apache server or http server or webserver all are the same things. Apache server plays a key role in the initial development of the world wide web. The name of apache was chosen out of respect to the Native American Tribe Apache and its superior skills in warfare strategy. Apache is developed and maintained by an open community of developers under apache software foundation.

The meaning from web server is that, we are not going to create a website, however we are going to create a platform that will run a website. Today mostly apache servers are running on the cloud machines.

Web server in case of redhat is HTTP and in case of Ubuntu it is apache. When we install HTTP on our machine, and restart the service, 8 threads of the apache will run concurrently. Threads mean child processes. When someone makes a hit on the web server, a new process thread will be created. More will be the traffic on your server, more will be the threads and more will be the resources utilized.

One of the major problem, that may exists in troubleshooting the apache is SElinux. If the tags are not defined carefully then your apache server may refuse to work.

Following is the simple guide to run your test site on redhat:

Install the package for apache as

# yum install httpd* -y

When done, create a test file in following location and add any test contents:

# vim /var/www/html/index.html

add the content:

This is a test site.

save the file and exit. 

Restart the service of apache to run the changes.

# /etc/init.d/httpd restart 

Now open the local browser and open with the name of localhost.

Enter the url: http://localhost

The webpage will open and display the above contents.

Also you can open the website with another name suppose your machine's ip is

open the file and add:

# vim /etc/hosts   

save and quit.

Now open the website with url

This is open the website you have created.

Installing RPM packages

Installing Extra Packages

When you are working with Operating system, you always need to install additional packages or softwares. The main advantage of Linux is that every software of this operating system is completely free. You can download the software from internet at no cost. Redhat operating system uses Redhat Package Manager (RPM) packages for installation. While installing the packages, you need to remember the architecture of your computer. Install only that package that support your system. For example, do not install 64 bit package on 32 bit architecture.

To install packages using command line :
# rpm -ivh package_name
This will replace the installed package with the new one. 

# rpm -Uvh package_name
This will remove the installed package.

# rpm -ev package_name

To see the list of packages installed.

# rpm -qa 

To see which file comes from which rpm.

# rpm -qf /etc/init.d/network


To install packages without full filling the dependencies.

# rpm -ivh package.rpm --nodeps

To see what files are extracted by a given package.

# rpm -ql rpmname

However, If we are going to install package one by one, It very long process. As we deal with the dependencies of the packages. So we have another tool known as 'YUM'.

yum is the utility that helps to install the packages automatically. It automatically resolve the dependencies and install the selected packages.

Redhat provides some of the packages along with the distribution. These packages are inside any ISO distribution of redhat.

Copy those packages to any location as;
# cp -rv /media/Packages/ /var/www/html/Packages/

# cd /var/www/html/Packages/

Install the package:

#rpm -ivh createrepo****.rpm

now run a command.

# createrepo -v /var/www/html/Packages/

Now edit a file;

# vim /etc/yum.repos.d/redhat.repo

enter the following text:


Now run the command:

# yum list all

If it shows the list of packages, means yum is configured on your machine.
After that use following command to install the packages:

# yum install package_name -y

# yum install php* -y

In this way you can install packages.

Creating Partitions

Creating Partitions

You can create partitions using command line. But firstly you should know what is the current partitioning table, for that

#fdisk -l

# df -h

These command will show you the existing partitions and where these partitions are mounted. In linux, mounting the partitioning is very necessary because without mounting the partitions you can't use the partition space. There are two ways of mounting the partitions. One is permanent way and other is temporary way.

To create the partition use the following command:

# fdisk /dev/sda

press m for more options, and press n for new partition, then press enter for initial address and enter +2G as last address. This will create 2GB partition. Then press w and write the partitioning table.

After that reboot the machine to work your partitions well.

This will create the new partition. But this new partition is not in use so far. For that create a new directory using

# mkdir /movies

Now mount the new partition on the directory.

For temporary mount:

# mount /dev/sda5 /movies

where sda5 is the new partition created. In your case the number may vary. Now check the mount using :

# df -h

For permanent mounting the partition, make entry in file

# vim /etc/fstab

/dev/sda5 movies ext4 defaults 0 0

The permanent mounted partition lasts after the reboot also as temporary partition doesn't.

Network Configuration

Network Configuration

Linux is a perfect networking operating system. It is highly secure if handled carefully. We can handle network of linux operating system in two ways:

1. Static IP allocation.

2. NetworkManager IP allocation.

3. Bridge Configuration.

We will learn above the methods one by one.

1. Static IP allocation:

Now open the file:

# vim /etc/sysconfig/network-scripts/ifcfg-eth0


save the file and quit. Make sure that you know the gateway address. Don't forget to restart the network service, It is necessary to restart the service so that new settings take place.

# /etc/init.d/network restart

Using this technique we can assign IP address permanently to a machine. We can also assign temporary IP as below:

# ifconfig eth0 netmask

This will temporarily set the IP address to given above, also we have to specify the interface on which we are giving the IP address. We can also bring down or bring up the interfaces manually using the below commands:

# ifup eth0
#ifdown eth0

2. Dynamic IP allocation:

Open the file:

# vim /etc/sysconfig/network-scripts/ifcfg-eth0


save the file and quit.

In this case restart the service of networkmanager as:
# /etc/init.d/NetworkManager restart
However, If the network is not managed yet, check for the following:

1. Check for the network cable, may be there is no cable.
2. Check for the interface on which cable is plugged, i.e. there may be two ethernet cards. In case you have two ethernet cards, run the command as:

# ethtool eth0
# ethtool eth1
# mii-tool

The above commands shows if the link is present or not.

3. In case, if link is not present, check your cable. It may be broken.

3. Network configuration for bridged network.

Stop the service of networkmanager as;

# /etc/init.d/NetworkManager stop;chkconfig NetworkManager off

Now edit the file ifcfg-br0 as;

# vim /etc/sysconfig/network-scripts/ifcfg-br0

Now open the file ifcfg-eth0 as;

# vim /etc/sysconfig/network-scripts/ifcfg-eth0


Don't forget to restart the service of network as;

# /etc/init.d/network restart

Directory Structure

Directory Structure

To understand the basic of linux, you have to remember the directory structure of the linux. The structure is however not complicated. It consists of a tree structure. The root of the tree is "/". Then there are a number of childs of / directory. It means that / contains a number of directories as listed below:








/etc consists of all the configuration files of the system.
/var is a standard subdirectory of the root directory and consists of logs, document root of the website etc.
/boot consists of the boot files of the system and it is a sensitive part of the system.
/root is the home directory root user.
/dev is the directory for the hardware devices
/bin contains all the binaries of the system.
/proc contains all the useful drivers for the system.

Basic Commands

Basic Commands

As you are interested in linux, you should have to know the basic linux commands. We will discuss here simple linux commands. For more help about the commands you can see man page for that command as;

# man commandname
To change directories, suppose you are in root directory, then

# cd /var/

this command will take you to inside the /var directory.

Where cd is the command used to change directories.

For more information about the command use man command as:

# man cd

If you want to check the contents in a directory use following command:

#ls /var/

you can use various options with in commands as:

# ls -l /var/

To create a file, use following commands:

# touch filename


# vim filename

press i for opening in insert mode and write contents in the file. to save the contents press escape and then :wq then press enter. The file will be saved.

To create a directory use following command, also note your location before creating directory.

# mkdir directoryname

To move and copy the files:

# mv /var/filename /tmp/filename

#cp /var/filename /tmp/filename

Here I have written /var/filename, it means you have to specify the complete path of the filename to move a specific file and location of the destination also. Same is the case with copy command.

To reboot and shutdown your system use following commands

# init 6

# init 0

To see the history of commands:

# history

Tuesday, 30 October 2012

Customize the CMD prompt

When you login the linux system for the first time, the following prompt you will see.

[root@localhost ~]#

This means you are login with root user with hostname localhost and you are in the root directory.

If you are logged in with a simple user's account then

[joy@localhost ~] $

What actually this means, We can also represent the above command line with below:


Change options for the prompt:

\d : the date Weekday Month Date format
\h : the hostname up to the first ‘.’
\A : the current time in 24-hour HH:MM format
\u : the username of the current user
\w : the current working directory, with $HOME abbreviated with a tilde
\$ : if the effective UID is 0, a #, otherwise a $

Also if we want to change this console that we see by default, we can change it as well. There is a variable called PS1, we need to edit that variable in order to customize the look of the prompt. To see the default value of the variable enter the below command:

[root@host1 ~] # echo $PS1

This is by default value, we need to customized values to this variable and our task is completed. Here are below some of the example:

[root@host1 ~] # export PS1='\e[0;36m[\u@\h \W]\$ \e[m '
[root: myself_sahil~]#

0;36m is for color specifications..

There are a few variable also that helps to customize the prompt. These are as below:

\a : an ASCII bell character (07)
\d : the date in "Weekday Month Date" format (e.g., "Tue May 26")
\D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
\e : an ASCII escape character (033)
\h : the hostname up to the first '.'
\H : the hostname
\j : the number of jobs currently managed by the shell
\l : the base name of the shell’s terminal device name
\n : newline
\r : carriage return
\s : the name of the shell, the base name of $0 (the portion following the final slash)
\t : the current time in 24-hour HH:MM:SS format
\T : the current time in 12-hour HH:MM:SS format
\@ : the current time in 12-hour am/pm format
\A : the current time in 24-hour HH:MM format
\u : the username of the current user
\v : the version of bash (e.g., 2.00)
\V : the release of bash, version + patch level (e.g., 2.00.0)
\w : the current working directory, with $HOME abbreviated with a tilde
\W : the base name of the current working directory, with $HOME abbreviated with a tilde
\! : the history number of this command
\# : the command number of this command
\$ : if the effective UID is 0, a #, otherwise a $
\nnn : the character corresponding to the octal number nnn
\\ : a backslash
\[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\] : end a sequence of non-printing characters

Create a colored prompt:

You may want to create a color prompt that you can use for visibility. In this example the hostname has been dropped to make a shorter prompt and the prompt is turned red but the commands that you enter will be black. The export command will change these features.

sahil@ub:~$ export PS1=’\e[0;31m[\u:\w]\$ \e[m ‘

This will color the prompt but not any commands that you enter.

List of Color codes:
Color Code
Black 0;30
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33
Blue 0;34
Green 0;32
Cyan 0;36
Red 0;31
Purple 0;35
Brown 0;33

Replace digit 0 with 1 for a lighter color.

Make Changes permanent:

All of the changes you make will be lost when you close the terminal or log out. Here are directions to make them permanent.


The .bashrc file in each user’s home directory allows you to change the default for the prompt to a color prompt by uncommenting the line:


Unfortunately a typo in the line must also be corrected so that it should read:

Ubuntu or CentOS
Place your custom prompt in the user .bashrc file with this command:

export PS1=’\e[0;31m[\u:\w]\$ \e[m ‘

Monday, 29 October 2012


MediaWiki is a free web-building software developed by Wikimedia foundation and others. It is used to create the websites in php. Its main utility in Wikipedia. It is used to run all of the foundation's projects, including Wikipedia, Wiktionary and Wikinews. It is written in php programming language and uses back end database.

The first version of the software was deployed to serve the needs of Wikipedia. Since then, it is deployed by many companies as content management system for internal knowledge management.

The software is optimized to correctly and efficiently handle projects of all sizes, including the largest wikis, which can have terabytes of content and hundreds of thousands of hits per second. Because Wikipedia is one of the world's largest websites, achieving scalability through multiple layers of caching and database replication has also been a major concern for developers. Wikipedia and other Wikimedia projects continue to define a large part of the requirement set for MediaWiki.

The software is highly customizable, with more than 700 configuration settings and more than 1800 extensions available for enabling various features to be added or changed. More than 600 automated and semi-automated bots and other tools have been developed to assist in editing MediaWiki sites.

Creating website using mediawiki:

Download the latest version of MediaWiki from the website:

The downloaded file is tar file.

Now for the users using Unix operating system, untar the file in the document root of the system as:

# cd /var/www/html/
# tar -xvf "name of the file"

rename the folder created as you want to publish on the website as:

# mv mediawiki.1.9 wiki/

Now open the url of your machine in the browser:

Now first step of the installation begins on the browser and continue as directed.

It will ask for the databases and name of the sites etc. Give the appropriate name as required.

Finish the installation.

Now if you want to change the settings related to server. visit the file in :

#cat /var/www/html/wiki/LocalSettings.php

Restart the database service and Apache service and continue with the website building.

Sunday, 28 October 2012

Eucalyptus Cloud Computing

Eucalyptus is opensource cloud computing software designed for private as well as public clouds. It pools together existing virtualized infrastructure to create cloud resources for compute, network and storage.
Today I am going to tell you how to install and operate Eucalyptus software that can help you to build the cloud VM instances.
VM instances are the instances, that are the end product of the software. We go through a number of steps to install Cloud software. In the VM instances we will have the IP of the virtual machine. We can enter that machine using various tools such as SSH and work on that machine. We can also clone that machine and use whenever we required.
Since I am working with opensource projects, so I will work with eucalyptus on RedHat Enterprise linux 5.6, however it doesn't matter which Operating system you are using.

Installation Steps:

1. Install rhel 5.6 on a machine, suggested machine should have larger resources than a normal machine. Also turn off the features such as firewall, IPtables etc on the boot time. Also ensure that yum is working on the system.

2. Download the java modules from the website. Following modules are sufficient.

a) jdk-6u29-linux-x64-rpm.bin

b) jre-6u29-linux-x64-rpm.bin

install using



3. Install ntp on the machine and sync your system with as

# yum install ntp

# ntpdate

4. Now install following packages, these are the dependencies for installing the main packages. Resolve the dependencies and install as:

# yum install -y ant ant-nodeps dhcp bridge-utils perl-convert-ASN1.noarch scsi-target-utils httpd

5. Download the main packages from following links:


Extract the downloaded tar files and create a repository from that. Copy those packages in a directory and make that make that repository available by yum. Now install the main eucalyptus tools as:

# yum install eucalyptus-cloud eucalyptus-cc eucalytpus-walrus eucalyptus-sc euca2ools

6. Restart the services of eucalyptus:

# /etc/init.d/eucalyptus-cc restart; chkconfig eucalyptus-cc on

#/etc/init.d/eucalytpus-cloud restart; chkconfig eucalytus-cloud on
Now Install a virtual machine on the same system, you can use KVM virtual machine. If you don't know how to do this, refer to my post KVM.

After you successfully install the virtual machine, create yum on that virtual machine in the same way as on the base machine.

On node controller(VM):

Now sync the time zone with as

# yum install ntp -y

# ntpdate

Now install xen on the virtual machine as:

# yum install xen -y

when completed, restart the system with xen kernel and modify the following:

# sed --in-place 's/#(xend-http-server no)/(xend-http-server yes)/' /etc/xend/xend-config.sxp

# sed --in-place 's/#(xend-address localhost)/(xend-address localhost)/' /etc/xend/xend-config.sxp

Restart the service of xend as:

# /etc/init.d/xend restart

Make sure that all the security features are disabled, for example, firewall IPTABLES. Now install the node controller on VM machine.

# yum install eucalyptus-nc -y

When completed open the configuration file of libvirtd and add

# vim /etc/libvirt/libvirt.conf

uncomment the following lines:


save and exit.

Now restart the service of node controller.

# /etc/init.d/eucalyptus-nc restart; chkconfig eucalyptus-nc on

This document describe the steps to install eucalyptus on single machine. However, these components if installed on different machines then we need to register all the components so that they can communicate with each other. For making these components to communicate with each other we will register all the components as:

We assume that all the components are installed and running.

# $EUCALYPTUS/usr/sbin/euca_conf --register-walrus

# $EUCALYPTUS/usr/sbin/euca_conf --register-cluster cluster_name

# $EUCALYPTUS/usr/sbin/euca_conf --register-sc cluster_name

# $EUCALYPTUS/usr/sbin/euca_conf --register-walrus
# $EUCALYPTUS/usr/sbin/euca_conf --register-walrus 
# $EUCALYPTUS/usr/sbin/euca_conf --register-nc "
# $EUCALYPTUS/usr/sbin/euca_conf --register-walrus" 

Where is the IP of the base machine and is the IP of the virtual machine. When all the components are registered successfully, login to


this will prompt you username and password, which by default set to admin and admin.

When you login, you will be forced to change the password for admin and your email address will be asked.

Now download the credentials from graphical menu.

# mkdir /.euca

# unzip euca2-admin* -d /.euca/

The above command will unzip the contents in the above directory. Run this command to use your credentials if required.

# . /.euca/eucarc

Now download the 64 bit image from following url:

# wget

Extract the downloaded image as:

To enable a VM image as an executable entity, a user/admin must add a root disk image, a kernel/ramdisk pair (ramdisk may be optional) to Walrus and register the uploaded data with Eucalyptus.
Each is added to Walrus and registered with Eucalyptus separately, using three EC2 commands. The following example uses the test image that we provide. Unpack it to any directory. Add the kernel to Walrus, and register it with Eucalyptus (WARNING: your bucket names must not end with a slash!):

# tar zxvf euca-centos-5.3-x86_64.tar.gz
# cd euca-centos-5.3-x86_64
# euca-bundle-image -i xen-kernel/vmlinuz- --kernel true
# euca-upload-bundle -b centos-kernel-bucket -m /tmp/vmlinuz-
# euca-register centos-kernel-bucket/vmlinuz-
# euca-bundle-image -i xen-kernel/initrd- --ramdisk true
# euca-upload-bundle -b centos-ramdisk-bucket -m /tmp/initrd-
# euca-register centos-ramdisk-bucket/initrd-
Next, add the root filesystem image to Walrus:

# euca-bundle-image -i centos.5-3.x86-64.img --kernel eki-8D7316E7 --ramdisk eri-87EE16CF
# euca-upload-bundle -b centos-image-bucket -m /tmp/centos.5-3.x86-64.img.manifest.xml
# euca-register centos-image-bucket/centos.5-3.x86-64.img.manifest.xml

=> Now, configure the dhcp server.

First copy the /usr/share/doc/dhcp3.0.5/dhcpd.conf.sample to /etc/dhcpd.conf

# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
# vim /etc/dhcpd.conf

Configure DHCP in this file.

=> Restart the service of dhcp

# /etc/init.d/dhcpd restart

Once the image is added, you can see the added image as:

# euca-describe-images
# euca-describe-instances
# euca-describe-avalability-zones
# euca-describe-keypairs

Adding keypair:

We add keypairs to ssh the remote computer with password authentication.
# euca-add-keypair mykey > mykey.private
Change the permission of mykey.private

#chmod 0600 mykey.private
Now run instances using following command:

# euca-run-instances -k mykey -n 1 <emi-id>

# euca-describe-instances

This will show the list of the instances, with ipaddresses.

Now ssh to the ip using following command.

# ssh -i .euca/mykey.private -l root -v

you will get the command line access of the vm created.

Cloud Computing

Cloud computing is the use of computing resources that are delivered as service over the network. Mainly three types of service models are there in cloud computing.
1. Infrastructure as a service
2. Platform as a service
3. Software as a service

1. Infrastructure as a service

In this service model, cloud providers offers computers, as physical or more often the virtual machines and other resources. The virtual machines are run as guest machine by hypervisors such as KVM or XEN.

Other resources in IAAS cloud includes image in virtual image library, raw and file based storage, load balancers, firewalls, ip addresses.

To deploy their applications, cloud users then install operating system images on the machines as well as there application softwares. In this model, it is the cloud user who is responsible for patching and maintaining the operating systems and application software. Cloud providers typically bill IaaS services on a utility computing basis, that is, cost will reflect the amount of resources allocated and consumed.

2. Platform as a service

In the PaaS model, cloud providers deliver a computing platformtypically including operating system, programming language execution environment, database, and web server. Application developers can develop and run their software solutions on a cloud platform without the cost and complexity of buying and managing the underlying hardware and software layers. With some PaaS offers, the underlying computer and storage resources scale automatically to match application demand such that cloud user does not have to allocate resources manually.

3. Software as a service

In this model, cloud providers install and operate application software in the cloud and cloud users access the software from cloud clients. The cloud users do not manage the cloud infrastructure and platform on which the application is running. This eliminates the need to install and run the application on the cloud user's own computers simplifying maintenance and support. What makes a cloud application different from other applications is its scalability. This can be achieved by cloning tasks onto multiple virtual machines at run-time to meet the changing work demand. Load balancers distribute the work over the set of virtual machines. This process is transparent to the cloud user who sees only a single access point. To accommodate a large number of cloud users, cloud applications can be multitenant, that is, any machine serves more than one cloud user organization.


Opensource is the word related to the computers community. The product in opensource you are dealing with is free of cost and whose sourcecode is shared with world. Opensource is one of the way to provide peoples free products. Everyone can make modifications in the softwares in opensource. If your modifications are liked by the users, your product can be enrolled as new version of the software.

Opensource is boon to general people as well as bigger organizations. However, it always seems to be paid product for larger organizations as they support for the product.