Wednesday, 23 October 2013

Backup of Linux Using dd command on Linux.

In some cases critical data loss will have a financial impact on companies. In my this blog i am updating 4 examples for using dd command to backup the Linux system. dd is a powerful Unix utility, Which is used by the Linux kernel to make boot images. dd command can only run by the root user or superuser. 

Warning: Please be careful while using dd command, If you don't know what you are doing, You will loss your data.

Example 1. - Hard Disk Backup (disk to disk)
We can use dd command to backup entire copy of a hard disk to another hard disk connected to the same system. run the dd command as shown below. In below example, the name of the source hard disk is /dev/sda and the name of the target hard disk is /dev/sdb.

# dd if =/dev/sda of =/dev/sdb

* Here "if" represents input file and "of " represents to output file, So the backup copy of /dev/sda will be available in /dev/sdb.
* If there are any errors, the above command will fail. Add the parameter "conv=noerror"
* Input file and Output file should be mentioned very carefully.

In the copy of hard disk to hard disk using dd command given below, sync option allows you to copy everything.

# dd if=/dev/sda of=/dev/sdb conv=noerror,sync

Example 2. - Create an Image of a Hard Disk
Instead of taking a backup of the hard disk, We can create an image file of the hard disk and save it. There are many advantages to backing up data to a disk image, This method is faster than other types of backups, and enabling you to quickly restore data.

# dd if=/dev/sda of=~/sdadisk.img

Example 3. - Restore Using Image Backup
To restore Image backup file on another hard disk, use the following dd command:

# dd if=sdadisk.img of=/dev/sdb

The image file sdadisk.img file, is the image of a /dev/sda, So the above command will restore the backup of /dev/sda to /dev/sdb.

Example 4. - Backup a Partition
We can use the device name of a partition in the input file, and in the output file we can specify target path or image file as shown in the below example:

# dd if=/dev/sda1 of=~/partition1.img

For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.

Monday, 21 October 2013

How to Mount NTFS Partition on Linux Step by Step.

For access to other drive or external hard drive in linux system you need to do the following:

Note: If you face any problem in any of the steps, Please add a comment and i'll get back with solution.

#yum install fuse fuse-ntfs-3g

If not able to install or getting something like,
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: centos.syn.co.il
* extras: centos.syn.co.il
* updates: centos.syn.co.il
Setting up Install Process
No package ntfs-3g available
No package ntfsprogs available

Don't Worry, you can download them using the following link, Just copy-paste it your browser and download will start:

#wget ftp://ftp.muug.mb.ca/mirror/fedora/epel/6/x86_64/ntfs-3g-2011.4.12-5.el6.x86_64.rpm

Once downloaded, Install the package:

#rpm -ivh ntfs-3g-2011.4.12-5.el6.x86_64.rpm

Now you should be able to open the ntfs partition by double clicking it.

For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.

Monday, 23 September 2013

Why yum grouplist and groupinstall command not working on Linux.

Whenever we are trying to install all the default packages by group using 'yum groupinstall groupname' command under RHEL v5.x. But, grouplist, groupinstall and groupdelete options are not working with yum.
How do I fix this issue and make sure yum command works with software groups under Redhat Enterprise Linux to increase productivity?

We need to install a package called yum-utils. its a collection of utilities that make yum easier and more powerful to use. 

Install yum-utils:
Type the following command:
# yum install yum-utils

To list software groups enter:
# yum grouplist


Loaded plugins: rhnplugin, security
Setting up Group Process
Installed Groups:
   Engineering and Scientific
   Graphics
   Network Servers
   System Tools
Available Groups:
   Administration Tools
   Authoring and Publishing
   Development Tools
   Editors
   Educational Software
   FTP Server
   Fedora Packager
   GNOME Desktop Environment
   GNOME Software Development
   Games and Entertainment
   Graphical Internet
   Hardware Support
   KDE (K Desktop Environment)
   KDE Software Development
   Mail Server
   News Server
   Office/Productivity
   Sound and Video
   Text-based Internet
   Web Development
   Web Server
   Window Managers
   X Window System
Done

To install "Web server" group, enter:
#yum groupinstall "Web server"

For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.


Wednesday, 10 July 2013

Configure open fire chat server on Linux.

Open-fire is a powerful instant messaging (IM) and chat server that Implements the XMPP protocols.

Server Installation:


1) Download and make a fresh installed Linux/CentOS latest version for 32/64 bits.


2) Download and install Jre-6u33-linux-i586.bin (jdk is not need just jre):


Get it here (or download from Internet)

http://www.oracle.com/technetork/java/javase/downloads/index.html
download jre-6u33-linux-i586.bin or Download tar.gz file.
Then configure.

chmod +x jre-6u33-linux-i586.bin Or

jre-6u33-linux-i586.bin Extract tar file
mv jre1.6.0_33/opt

3) #mysql - u root -p;

     #mysql>CREATE DATABASE openfire;
     #mysql>quite;

4) Download and Install openfire - openfire_3_7_1 tar.gz

    #tar xvfz openfire_3_7_1 tar.gz
    #mv openfire /opt

    # cd /opt/openfire/bin


Uncomment and modify the following line at the beginning of "/opt/openfire/bin/openfire" script to override "JAVA_HOME":

INSTALL4J_JAVA_HOME_OVERRIDE=/opt/jre1.6.0_33


Note: This is not need if "echo $JAVA_HOME" point to a valid ORACLE java 1.5 (or later) or OPENJDK installation path.

Openfire does not works with "gcj" which can be installed on Ubuntu, check installed version executing "java-version".

Then just Start it!


./openfire start


5) Next, edit the configuration file /etc/openfire/openfire.xml, and add your linux server's public IP address in the <interface> section, and removing the "<!-->" comment markers that surround this section.


Edit in /etc/openfire/openfire.xml file


<interface>192.168.21.8</interface>


Now restart the Openfire with the following command:


/etc/init.d/openfire restart


Now access to openfire server - http://192.168.21.8:9090


For any query please feel free to contact me by this mail ID - sashwatkatore@gmail.com


Tuesday, 18 June 2013

Configure Squirrelmail Webmail Server on Linux.

Configure Squirrelmail Server with POP3/IMAP on Linux/CentOS
Package Requirements:
* Linux Server with Centos 5/6
* Apache 2 with PHP4 or later
* Postfix (SMTP server or MTA)
* Dovecot ( IMAP/POP3 server)
* Squirrelmail (A free Webmail)
We will be setting up the email server for local users where they can use
webmail or outlook express to access their email. We will be setting up a simple
and most basic mail server for local users.
Before we proceed to setup a mail server, the following 3 are most important
for delivering email to destination.
1. DNS Entry for your mail server with MX record
2. Setup an SPF record
3. Setup Domain Name Keys
4. Reverse IP for your Mail Server
The most important of it setting up reverse IP for your mail server. You have
to ask your hosting provider to setup a reverse IP for your mail server. 
Install Postfix (SMTP Server/MTA)
Postfix is fast and popular SMTP server and widely used. Its main job is to
relay mail locally or to intended destination outside the network.
By default Sendmail comes Pre-installed with Centos. We will need need to remove
it and install Postfix:
#yum remove sendmail
#yum install postfix
The configuration file is located at /etc/postfix/main.cf. 
Edit the file and make sure you change the following lines with your domain name:
myhost = mail.sumit.com
mydomain = sumit.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, $mydomain

we have to be careful about $mydestination is because it restrictions receiving
Setting up SASL + TLS
To enable SASL authentication open /etc/postfix/main.cf and
Install Dovecot (POP3/IMAP Server)
Look for the line auth default and make these changes. Becareful with the lines as they are heavily commented out:
Install Squirrelmail
Before you access Squirrelmail or Mail restart all the services:
To access squirrelmail point your browser to

emails by the server pertaining to domains.

We have to also setup SASL with our postfix to authenticate our users who want
to send email outside of the permitted network:
#yum install cyrus-sasl

add the following lines:
smtpd_sasl_auth_enable = yes
smtpd_reciptient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth

Dovecot is a very popular POP3/IMAP server. The main difference between POP3
and IMAP is while accessing the your email with outlook if you use POP3 the
mail is downloaded to your computer and deleted from the server. With IMAP the

mail is retained in the server. 
The configuration file is located at /etc/dovecot.conf
#yum install dovecot
Open the dovecot config file /etc/dovecot.conf and make the following changes. 
You may need to comment or uncomment certain lines:
protocols = imap imaps pop3 pop3s

auth default {
mechanisms = plain login
passdb pam {
}
userdb passwd {
}
socket listen {
clinet {
path = /var/spool/postfix/private/auth/
mode = 0660
user = postfix
group = postfix
}
}
}

Squirrelmail is a free webbased email can be very handy for your users to login

while they are mobile.
#yum install squirrelmail
To setup the squirrelmail under apache, open /etc/httpd/conf/httpd.conf:
and insert the following lines:
Alias /squirrelmail /usr/local/squirrelmail/www
<Directory /usr/local/squirrelmail/www>
Options Indexes
AllowOverride none
DirectoryIndexes index.php
Order allow,deny
allow from all
</Directory>

The squirrelmail configuration utility is located in /usr/share/squirrelmail/config/conf.pl:
Run the configuration utility and set the server settings to SMTP and change your domain name to sumit.com
/usr/share/squirrelmail/config/conf.pl

/etc/init.d/postfix start
/etc/init.d/dovecot start
/etc/init.d/saslauthd start
service httpd restart

http://www.sumit.com/webmail
and the squirrelmail test page is located at http://domain.com/webmail/src/configtest.php
Before we login to squirrelmail, you will need to create users:
Just create a localuser with adduser:
#adduser sumit
and update the password of sumit
# passwd sumit

Now open Squirrelmail server with the username & password.
For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.

Configure phpMyAdmin 4.2.11 on Linux.


 phpMyAdmin is a free software tool written in php, intended to handle the administration of MySQL over the web. phpMyAdmin supports a wide range of operations with MySQL. 

phpMyAdmin Installation on Linux:

(Note: First Install all the related files to run MySQL, php, Apache)

#yum install httpd*

#yum install php-mysql*
#yum install mysql-server

configure your Apache web server(if you have any problem regarding that you can look in my previous post "How to configure Apache or httpd Server")


check in the /etc/httpd/conf.d that there is php.conf file is present


start all the required services 


#service httpd start


#service mysqld start


#chkconfig httpd on


#chkconfig mysqld on


Download the latest version of  phpmyadmin Currently the stable version of phpMyAdmin is 4.2.11


After downloading it uncompressed it


#tar -xjvf php ....................... (depending upon the version u downloaded)


move this folder to your web directory in which your site is located and rename it as i have done php and open the configuration file, make changes to the settings so that you can access it via http:


#vi config.inc.php


make changes into line no. 73


73 $cfg['Servers'][$i]['auth_type']    ='http';     (enter http here in =''; line no. 73)


:wq            

(save and quite)

restart the httpd service and access it via web browser, inter in the address browser your IP/php to access.


#service httpd restart

in web browser your IP/php

If you had set any password for your mysql than use that other wise it will be blank


username: root


password: blank


If you want to know the username and password of your phpMyAdmin go to:


#vi config.inc.php


and see in line no. 74 & 75 - 


74   $cfg['Servers'][$i]['user']       ='root';              (MySQL user)


75   $cfg['Servers'][$i]['password']   ='';                 (MySQL password)


For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.

Friday, 7 June 2013

Configure ftp Server on Linux.

Though the steps provided here are tested in CentOS 6.5, it should work on RHEL and Scientific Linux 6.x too. In this blog my ftp server IP and hostname are 192.168.21.10 and sumit.com respectively. 

Before proceed, stop the firewall.

[root@sumit.com ~]# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@sumit.com ~]# service ip6tables stop
ip6tables: Flushing firewall rules:                        [  OK  ]
ip6tables: Setting chains to policy ACCEPT: filter         [  OK  ]
ip6tables: Unloading modules:                              [  OK  ]
[root@sumit.com ~]# chkconfig iptables off
[root@sumit.com ~]# chkconfig ip6tables off
[root@sumit.com ~]# 

Now let us install FTP service.

[root@sumit.com ~]# yum install -y vsftpd
[root@sumit.com ~]# Start vsftpd service.
[root@sumit.com ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@sumit.com ~]# 

Enable vsftpd in multi-user levels.

[root@sumit.com ~]# chkconfig vsftpd on
Now edit the /etc/vsftpd/vsftpd.conf file. 
Uncomment and edit the lines in the vsftpd.conf file which are shown in bold.

[root@sumit.com ~]# cat /etc/vsftpd/vsftpd.conf 

# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# The target log file can be vsftpd_log_file or xferlog_file.
# This depends on setting xferlog_std_format parameter
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# The name of log file when xferlog_enable=YES and xferlog_std_format=YES
# WARNING - changing this filename affects /etc/logrotate.d/vsftpd.log
#xferlog_file=/var/log/xferlog
#
# Switches between logging into vsftpd_log_file and xferlog_file files.
# NO writes to vsftpd_log_file, YES to xferlog_file
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES
ascii_download_enable=YES
#
# You may fully customise the login banner string:
ftpd_banner=Welcome to OSTECHNIX FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
use_localtime=YES

Now let us restart the vsftpd service and try to connect to ftp server.
[root@sumit.com ~]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
Connect to the ftp server

Note: Root is not allowed to connect to ftp server by default for security purpose. So lets us create a new user called ftpuser

[root@sumit.com ~]# useradd ftpuser
[root@sumit.com ~]# passwd ftpuser
Changing password for user ftpuser.
New password: 
BAD PASSWORD: it is based on a dictionary word
Retype new password: 
passwd: all authentication tokens updated successfully.

Connet to FTP server using the new user ftpuser.
[root@sumit.com ~]# ftp 192.168.21.10
-bash: ftp: command not found
[root@sumit.com ~]# 

Oops! ftp package is not installed. So let us install ftp package first.

[root@sumit.com ~]# yum install -y ftp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ftp.i686 0:0.17-51.1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
 Package       Arch           Version                 Repository           Size
================================================================================
Installing:
 ftp           i686           0.17-51.1.el6           localrepo            55 k
Transaction Summary
===============================================================================================
Install       1 Package(s)
Total download size: 55 k
Installed size: 91 k
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : ftp-0.17-51.1.el6.i686                                       1/1 
  Verifying  : ftp-0.17-51.1.el6.i686                                       1/1 
Installed:
  ftp.i686 0:0.17-51.1.el6                                                      
Complete!

[root@sumit.com ~]# 
Again connect to the FTP server.
[root@sumit.com ~]# ftp 192.168.21.10
Connected to 192.168.1.200 (192.168.21.10).
220 Welcome to ftpuser FTP service.
Name (192.168.21.10:root): ftpuser
331 Please specify the password.
Password:
500 OOPS: cannot change directory:/home/ostechnix
Login failed.
ftp> 

It shows a error that the user cannot change to his $HOME directory. Type exit to return back from the ftp console and allow vsftpd daemon to change users into their $HOME directories. To do that update SELinux configuration using the command below.

[root@sumit.com ~]# setsebool -P ftp_home_dir on
And finally connect to the FTP server.

[root@sumit.com ~]# ftp 192.168.21.10
Connected to 192.168.21.10 (192.168.21.10).
220 Welcome to ftpuser FTP service.
Name (192.168.21.10:root): ftpuser
331 Please specify the password.
Password:

230 Login successful.

Remote system type is UNIX.
Using binary mode to transfer files.
ftp> pwd
257 "/home/ostechnix"
ftp> 
Its working now. You can use your FTP server.
Connect to FTP server using Filezilla from Client:

Download and install Filezilla client software to any one of the client systems. Open the Filezilla client and enter the username and password which we have created earlier and click connect.

For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.