Pages

Unixbhaskar's Blog

Tuesday, January 25, 2011

How to fix security loophole in Gentoo


Security is an ongoing matter for all the open system. So it's upto the guy who in charge of it and some company forces it too.In this article I will show you how you can fix the security hole in Gentoo.

Say you come to know that an security vulnarability has found on some particular and that software were loaded in your box.Here is how you can fix those:


bhaskar@bhaskar-laptop_15:03:56_Tue Jan 25:~> sudo glsa-check -f all
fixing 200812-12
fixing 200802-11
fixing 200705-23
fixing 200406-17
fixing 200804-13
fixing 200409-20
fixing 200708-01
fixing 200801-18
fixing 201001-04
fixing 201011-01
fixing 200909-11
fixing 200509-13
fixing 200612-16
fixing 200606-25
fixing 200405-22
fixing 200711-17
fixing 200510-19
fixing 201006-20
fixing 200602-08
fixing 200310-03
fixing 200506-16



....output is omitted for the sake of brevity, Yes,you spotted it right,glsa-check is an utility in Gentoo system to check security.Once it finished running then just run this command with different arguments; like below:


bhaskar@bhaskar-laptop_15:05:34_Tue Jan 25:~> sudo glsa-check -l affected
[A] means this GLSA was already applied,
[U] means the system is not affected and
[N] indicates that the system might be affected.



Now let me tell you that those alphabet in the left side within square bracket come with different colors. The A will be on normal white,the U will be green and the N in red.Important part to check how many N you have .

So,one tiny utility can do wonder,indeed.You can put it into the cron to run it periodically.

Hope this will help.

Cheers!
Bhaskar

Thursday, January 13, 2011

MySQL : A little security tip

In this article I am going to show you a little trick about MySQL ,which might help you to prevent some attack on production database server.Every MySQL server has a root user attached to it and for intruders it's very easy to guess that and launch attack on it.

Here is how you can change the root user name for that MySQL server :


bhaskar@bhaskar-laptop_08:55:51_Thu Jan 13:~> sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 5.1.51-log Gentoo Linux mysql-5.1.51

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>use mysql;
mysql> update user set password=PASSWORD("NEWPASSWORD") where
User='';
mysql> flush privileges;
mysql> quit


That's all!!

Hope this will help.

Cheers!
Bhaskar

Wednesday, December 15, 2010

Fetch mail from Gmail through Mutt

Mutt  is a wonderful mail client ,which is commandline based. I have been using it for quite some time now.In this article I will show you how you can get mail from your gmail account.

If you don't have it then please get it from the specific OS repository or the link provided at the begining of this article.

I am sitting on Gentoo and I got it like below:


bhaskar@bhaskar-laptop_09:46:16_Wed Dec 15:~> sudo emerge -av mutt
Password:

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild R ] mail-client/mutt-1.5.20-r18 USE="berkdb crypt gdbm nls ssl -debug -doc* -gnutls* -gpg* -idn -imap* -mbox* -nntp -pop* -qdbm -sasl* -sidebar -smime* -smtp* -tokyocabinet" 0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

Would you like to merge these packages? [Yes/No]




So I already have it in my system so there is no point getting it again.Let me check out when I got this;

bhaskar@bhaskar-laptop_09:49:46_Wed Dec 15:~> sudo genlop -t mutt
* mail-client/mutt

Wed Nov 24 11:16:02 2010 >>> mail-client/mutt-1.5.20-r18
merge time: 10 minutes and 53 seconds.



Anyway ,it deflates configuration files in /etc/mutt like below:


bhaskar@bhaskar-laptop_09:51:46_Wed Dec 15:/etc/mutt> ls
Muttrc Muttrc.dist mime.types mime.types.dist



Now What I do;read few article on the internet about gmail integration with mutt(which I will provide the link in the resource section at the bottom of this post).Now I have copied the Muttrc file to my home dir and make adjustment to that file.

My personal .Muttrc look like below:



1 # Some minimal Mutt settings, Gentoo-style. Since mutt was installed
2 # with USE=mbox, this file doesn't have any changes from the default
3 # mutt settings, making it very minimal indeed...
4 #
5 # Please don't add settings to this file to change other user
6 # preferences (such as colors), since those can be hard for a user to
7 # undo if their preference doesn't match yours! For example, it is
8 # *impossible* currently in mutt to remove color settings from objects
9 # other than the index.
10 #
11
12 set imap_user="unixbhaskar@gmail.com"
13 set imap_pass=""
14 set pager_context=1
15 set pager_index_lines=6 #show a mini-index in pager
16 set menu_scroll
17 set pgp_verify_sig=no #dont show pgp in pager
18 set status_on_top #put status line at top
19 set sort=threads #sort by message threads in index
20 #
21 set status_format=" %r %b %f %n Del %d Msgs %m %l %> (%P)"
22 set pager_format="%-10.10i %[!%a %b %d %R]"
23 set date_format="!%H:%M %a %d %b "
24 set index_format="%4C %Z %[%b%d] %-15.15F %s"
25 set folder_format="%2C %t %8s %d %N %f"
26 #
27 # #set sendmail="/usr/bin/nbsmtp -d isp.net -h smtp.isp.net -f yourname@isp.net"
28 #
29 set from="unixbhaskar@gmail.com" #set to your from address
30 set realname="Bhaskar Chowdhury"
31 #
32 # set record="$home/sent" #sent mail is saved here
33 set delete=yes #delete without prompting
34 set include=yes #quote msg in reply
35 set fast_reply=yes #no prompting on reply
36 set beep=no #no noise
37 set markers=no #no + on wrapped lines
38 set confirmappend=no #no prompt for save to =keep
39 set to_chars=" +TCF" #no L for mail_list
40 #
41 set folder = "imaps://imap.gmail.com:993"
42 set spoolfile = "+INBOX"
43 set postponed ="+[Gmail]/Drafts"
44
45 set header_cache =~/.mutt/cache/headers
46 set message_cachedir =~/.mutt/cache/bodies
47 #mailboxes =inbox
48 # mailboxes =gentoo-dev
49 # mailboxes =gentoo-announce
50 # mailboxes =gentoo
51 # mailboxes =freshmeat
52 # mailboxes =duplicates
53 # mailboxes =default
54 # mailboxes =friends
55 # mailboxes =junk
56 # mailboxes =spam
57 # mailboxes =keep
58 #
59 set smtp_url = "smtp://unixbhaskar@smtp.gmail.com:587/"
60 set smtp_pass = ""
61 save-hook .* =keep #default mbox to (s)ave mail is =keep
62 # subscribe gentoo-user gentoo-dev #subscribed to these lists
63 #
64 # bind pager h display-toggle-weed #toggle headers with h key
65 #
66 # # simulate the old url menu
67 macro index \cb |urlview\n 'call urlview to extract URLs out of a message'
68 macro pager \cb |urlview\n 'call urlview to extract URLs out of a message'
69 #
70 # #run fetchmail by hitting key of G
71 macro index G "!fetchmail -a -m 'procmail -d %T'\r"
72 macro pager G "!fetchmail -a -m 'procmail -d %T'\r"
73 #
74 # #use to edit .muttrc and then source it...no restart necessary
75 # macro generic ,sm ":source $HOME/.muttrc\r"
76 # macro generic \cj "!rxvt -bg wheat -e joe $HOME/.muttrc\r"
77 #
78 # # default list of header fields to weed out when displaying mail
79 # #ignore them all and then unignore what you want to see
80 # ignore *
81 unignore Date To From: Subject X-Mailer Organization User-Agent
82 hdr_order Date From To Subject X-Mailer User-Agent Organization
83 #
84 # ##your Mutt has to have some colors
85 # ##these are for four levels of quoted text
86 # ##they override the system settings in /etc/mutt/Muttrc
87 #
88 # #color quoted green default
89 color quoted1 magenta blue
90 # #color quoted2 yellow default
91 # #color quoted3 red default
92 # #color signature cyan cyan
93 #
94 #
95 # #this color setup is copied from /etc/mutt/Muttrc.color
96 # #comment it out if you want the default colors in /etc/mutt/Muttrc
97 # # Je vois la vie en rose :-)
98 color hdrdefault brightcyan blue
99 color header brightwhite blue "^from:"
100 color header brightwhite blue "^subject:"
101 #
102 color quoted brightgreen blue
103 color signature brightwhite blue
104 #
105 color indicator blue green
106 #
107 color error red black
108 mono error bold
109 color status black cyan
110 mono status bold
111 color tree yellow blue
112 #
113 color tilde brightmagenta blue
114 color body brightwhite blue "[-a-z_0-9.]+@[-a-z_0-9.]+"
115 mono body bold "[-a-z_0-9.]+@[-a-z_0-9.]+"
116 color body brightyellow black "^Good signature"
117 mono body bold "^Good signature"
118 color body brightwhite red "^Bad signature from.*"
119 mono body bold "^Bad signature from.*"
120 color normal white blue
121 color message green black
122 color attachment brightgreen blue
123 #
124 # # End of file...but it can go on and on and on....:)
125 #



So the next job is to invoke mutt from the commandline like below:


mutt


and here is the outcome of that..it's connecting to gmail..


Now look at the bottom of the picture it fetching the header of those messages(it doesn't download the whole message).Only when you select the message for viewing then only mutt download the whole message.Once it get the headers it shows off the inbox like below:




Once the the headers are fetched it display the mail boxes you have with Gmail.Then you need to choose the proper box to show off those mails reside in it.Now select the any inbox and press enter then:



Anyway you can also integrate GnuPG with it for encryption and signing.




Hope this will help.

Cheers!
Bhaskar


Resources:

1) http://www.andrews-corner.org/mutt.html

2) http://wiki.mutt.org/index.cgi?MuttGuide

3) http://crunchbanglinux.org/wiki/howto/howto_setup_mutt_with_gmail_imap

4) http://www.faqs.org/docs/Linux-HOWTO/Mutt-GnuPG-PGP-HOWTO.html

Friday, November 19, 2010

NetSurf - A graphical-browser for emergency browsing

In this post I will investigate a commandline graphical browser(run without X) which I was unaware of till two days back.I am pretty much well versed with lynx and elinks. . The new found(mentioned the source in the resource section at the bottom of the post) one called netsurf .I have tried to install it from the source available on Fedora 12 ,but failed to do so due to lack of patience.

Now I am sitting on Debian Lenny as it in the repository so it;s really make easy to install and use it.So I get it like below:


bhaskar@bhaskar-laptop_06:00:11_Fri Nov 19:~> sudo aptitude install netsurf
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
The following NEW packages will be installed:
netsurf
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 411kB of archives. After unpacking 1217kB will be used.
Writing extended state information... Done
Get:1 http://http.us.debian.org stable/main netsurf 1.2-1 [411kB]
Fetched 411kB in 1min52s (3641B/s)
Selecting previously deselected package netsurf.
(Reading database ... 112830 files and directories currently installed.)
Unpacking netsurf (from .../netsurf_1.2-1_i386.deb) ...
Processing triggers for menu ...
Processing triggers for man-db ...
Setting up netsurf (1.2-1) ...
Processing triggers for menu ...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Writing extended state information... Done
Reading task descriptions... Done


Once it is installed it just a cakewalk.I invoked it like below:

bhaskar@bhaskar-laptop_06:07:41_Fri Nov 19:~> /usr/bin/netsurf http://linux-nfs.org

(netsurf:5351): libglade-WARNING **: could not find signal handler 'on_menupopup_navigate_activate'.

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem

(netsurf:5351): Gtk-WARNING **: gtk_menu_attach_to_widget(): menu already attached to GtkMenuItem



Now the gtk-thing pop up like below;



Now few noticeable thing about it that it doesn't support tab feature.And lot of normal plug-in might be missing.But in case of headless server it will be as useful as other cli-browser.Second it heavily depend on GTK, so you have to have it installed in the system to get it work.

Plus you need to check out the dependency when building from source from their web site to get it straight.

Resources:

1) http://soosck.wordpress.com/2010/11/16/netsurf-graphical-web-browser-command-line-css/

Hope this will help.

Cheers!
Bhaskar

Wednesday, November 17, 2010

The mystery behind LUN(Logical Unit Number)

After being amazed and bewildered for sometime and listening to people talking so geeky about it ;I decided to unearth few intricacies about it.As we all know few parts of the world where people making simple thing complicated to others which benifit few blunt headed idiots to get cheap credit and save thier arse.

Oh! by the way forgot to mention that(those of you ignore the title)this is all about telling some intricacies about LUN(Logical Unit Number) .So without much ado lets dive into it.

Let me give you a clear cut definition I have come across so far is this "A LUN is a Logical Unit Number. It can be used to refer to an entire physical disk, or a subset of a larger physical disk or disk volume. The physical disk or disk volume could be an entire single disk drive, a partition (subset) of a single disk drive, or disk volume from a RAID controller comprising multiple disk drives aggregated together for larger capacity and redundancy. LUNs represent a logical abstraction or, if you prefer, virtualization layer between the physical disk device/volume and the applications."

So how can you detect the LUN?

So there are two common ways to detect it,one is through /proc filesystes check and second is create a initrd image with it so time of os boot it can be detected.

Take the first case by scanning the /proc filesystem check; we need to the following to get a sense of it or aware of it:


bhaskar@bhaskar-laptop_06:55:52_Wed Nov 17:~> sudo cat /proc/scsi/scsi
Password:
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: ATA Model: ST9160821AS Rev: 3.BH
Type: Direct-Access ANSI SCSI revision: 05
Host: scsi3 Channel: 00 Id: 00 Lun: 00
Vendor: Optiarc Model: DVD RW AD-7560A Rev: DH10
Type: CD-ROM ANSI SCSI revision: 05


As you can see it from the out of that scan of /proc filesystem.Now the next one getting the LUN thing detected when the os boots.

Detect LUNs automatically at system boot

The second method of configuring LUNs for a Linux system with only LUN 0 configured involves setting the parameter for the SCSI mid-layer driver that controls how many LUNs are scanned during a SCSI bus scan. The following procedure works for both 2.4 and 2.6 kernels, but it assumes the SCSI mid-layer driver is compiled as a scsi_mod module that is loaded automatically at system boot time. For Linux 2.4 kernels, to set the maximum number of disk devices under Linux to properly detect all volumes, you need to set the max_scsi_luns option for the SCSI mid-layer driver. For example, if max_scsi_luns is set to 1 this limits SCSI bus scans to only LUN 0. This value should be set to the respective maximum number of disks the kernel can support, for example, 128 or 256. In Linux 2.6 kernels, the same procedure applies, except that the parameter has been renamed from max_scsi_luns to max_luns.

1. Edit the /etc/modules.conf file.
2. Add the following line:
* options scsi_mod max_scsi_luns= (where is the total number of luns to probe.
3. Save the file.
4. Run the mkinitrd command to rebuild the ram-disk associated with the current kernel. You can use the following figures examples of what mkinitrd command to run for your operating system. refers to the ‘uname –r’ output which displays the currently running kernel level, for example:. 2.4.21-292-smp.
For SUSE distributions, use the following command:

cd /boot
mkinitrd –k vmlinuz- -i initrd-

For Red Hat distributions, use the following command:

cd /boot
mkinitrd –v initrd-.img

5. Reboot the host.
6. Verify that the boot files are correctly configured for the newly created initrd image in the /boot/grub/menu.lst file.

The basics behind it somewhat is this LUNs are created as a basic part of the storage provisioning process using software tools that typically accompany the particular storage platform. However, there is not a 1-to-1 ratio between drives and LUNs. Many LUNs can easily be carved out of a single disk drive.

For example, a 500 GB drive can be partitioned into one 200 GB LUN and one 300 GB LUN, which would appear as two unique drives to the host server. Conversely, storage administrators can employ Logical Volume Manager software to combine multiple LUNs into a larger volume. Veritas Volume Manager from Symantec Corp. is one example of this software. In actual practice, disks are first gathered into a RAID group for larger capacity and redundancy (e.g., RAID-50), and then LUNs are carved from that RAID group.

LUNs are often referred to as logical "volumes," reflecting the traditional use of drive volume letters, such as volume C: or volume F: on your computer. But some experts warn against mixing the two terms, noting that the term "volume" is often used to denote the large volume created when multiple LUNs are combined with volume manager software. In this context, a volume may involve numerous LUNs and can confuse storage allocation.

Once created, LUNs can also be shared between multiple servers. For example, a LUN might be shared between an active and standby server. If the active server fails, the standby server can immediately take over. However, it can be catastrophic for multiple servers to access the same LUN simultaneously without a means of coordinating changed blocks to ensure data integrity. Cooordinating data changes requires clustering software, such as a clustered volume manager, a clustered file system, a clustered application or a network file system using NFS or CIFS.


LUN scaling and performance

LUNs are based on disks, so LUN performance and reliability will vary for the same reasons. For example, a LUN carved from a Fibre Channel 15K rpm disk will perform far better than a LUN of the same size taken from a 7,200 rpm SATA disk. This is also true of LUNs based on RAID arrays where the mirroring of a RAID-0 group may offer significantly different performance than the parity protection of a RAID-5 or RAID-6/dual parity (DP) group. Proper RAID group configuration will have a profound impact on LUN performance.

An organization may utilize hundreds or even thousands of LUNs, so the choice of storage resources has vast implications for a storage administrator. Not only is it necessary to supply an application with adequate capacity (in gigabytes), but the LUN must also be drawn from disk storage with suitable characteristics.

LUN management tools

Since an enterprise array may host more than 10,000 LUNs, software tools are vital for efficient LUN creation, manipulation and reporting. Such management tools are readily available; almost every storage vendor provides some type of management software to accompany products ranging from direct-attached storage (DAS) devices to enterprise arrays.

Administrators typically opt for vendor-specific or heterogeneous tools. A data center with one storage array or a single-vendor shop would do well with the indigenous LUN management tool that accompanied their storage system. Multivendor shops should at least consider heterogeneous tools that allow LUN management across all of the storage platforms.


A LUN management tool should also support the entire storage provisioning process. Features should include mapping to specific array ports and masking specific host bus adapters (HBA), along with comprehensive reporting. The LUN management tool should also be able to reclaim storage that is no longer needed. Although a few LUN management products support autonomous provisioning, some administrators have reservations about such automation.

SAN zoning and masking

LUNs are the basic vehicle for delivering storage, but provisioning SAN storage isn't just a matter of creating LUNs or volumes; the SAN fabric itself must be configured so that disks and their LUNs are matched to the appropriate servers. Proper configuration helps to manage storage traffic and maintain SAN security by preventing any server from accessing any LUN.

Zoning makes it possible for devices in a Fibre Channel network to see each other. By limiting the visibility of end devices, servers (hosts) can only see and access storage devices that are placed into the same zone. In more practical terms, zoning allows certain servers to see one or more ports on a disk array. Bandwidth, and thus minimum service levels, can be reserved by dedicating certain ports to a zone or isolate incompatible ports from one another.

Zoning is an important element of SAN security and high-availability SAN design. Zoning can typically be broken down into hard and soft zoning. With hard zoning, each device is assigned to a zone, and that assignment can never change. In soft zoning, the device assignments can be changed by the network administrator.

LUN masking adds granularity to this concept. Just because you zone a server and disk together doesn't mean that the server should be able to see all of the LUNs on that disk. Once the SAN is zoned, LUNs are masked so that each host server can only see specific LUNs.

Suppose that a disk has two LUNs: LUN_A and LUN_B. If we zoned two servers to that disk, both servers would see both LUNs. However, we can use LUN masking to allow one server to see only LUN_A and mask the other server to see only LUN_B. Port-based LUN masking is granular to the storage array port, so any disks on a given port will be accessible to any servers on that port. Server-based LUN masking is a bit more granular; a server will see only the LUNs assigned to it, regardless of the other disks or servers connected.

Adding/Removing a Logical Unit Through rescan-scsi-bus.sh

The sg3_utils package provides the rescan-scsi-bus.sh script, which can automatically update the logical unit configuration of the host as needed (after a device has been added to the system). The rescan-scsi-bus.sh script can also perform an issue_lip on supported devices. For more information about how to use this script, refer to rescan-scsi-bus.sh --help.
To install the sg3_utils package, run yum install sg3_utils.

Known Issues With rescan-scsi-bus.sh

When using the rescan-scsi-bus.sh script, take note of the following known issues:

In order for rescan-scsi-bus.sh to work properly, LUN0 must be the first mapped logical unit. The rescan-scsi-bus.sh can only detect the first mapped logical unit if it is LUN0. The rescan-scsi-bus.sh will not be able to scan any other logical unit unless it detects the first mapped logical unit even if you use the --nooptscan option.

A race condition requires that rescan-scsi-bus.sh be run twice if logical units are mapped for the first time. During the first scan, rescan-scsi-bus.sh only adds LUN0; all other logical units are added in the second scan.

A bug in the rescan-scsi-bus.sh script incorrectly executes the functionality for recognizing a change in logical unit size when the --remove option is used.

The rescan-scsi-bus.sh script does not recognize ISCSI logical unit removals.


Resources:

1) http://publib.boulder.ibm.com/infocenter/dsichelp/ds6000ic/index.jsp?topic=%2Fcom.ibm.storage.smric.help.doc%2Ff2c_linuxlunconfig_2hsaga.html

2) http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/html/Online_Storage_Reconfiguration_Guide/rescan-scsi-bus.html

Hope this will help.

Cheers!
Bhaskar

Friday, November 5, 2010

Let's deal with oddity : Remove filename with special char in them

Let's face it,everyone face some oddity sooner then later to deal with open system.I have had come across quite a lot over the decade and am going to share few in this article.

Sometime people forget the basic thing and make things complicated. Like when they create a simple file they put arcane character in the name and it will create havoc in later stage.For example if someone create a file with "--" or "#" or some other character in the filename.Say one has a filename like below:


bhaskar@bhaskar-laptop_18:35:12_Fri Nov 05:~> touch -- -hey


Now you cannot list it like below:

bhaskar@bhaskar-laptop_18:38:52_Fri Nov 05:~> ls -l -hey
ls: invalid option -- 'e'
Try `ls --help' for more information.


Or

delete it like below;

bhaskar@bhaskar-laptop_18:39:00_Fri Nov 05:~> rm -f -hey
rm: invalid option -- 'h'
Try `rm ./-hey' to remove the file `-hey'.
Try `rm --help' for more information.


Now this is hindering you to get rid of it or even worse to take backup from the system if that file included in the backup list.So how to get rid of it ..as we all know that file store all the information in inode..so get it..

bhaskar@bhaskar-laptop_18:42:19_Fri Nov 05:~> ls -i | grep hey
655109 -hey



Now you can get rid of that file by inode like below:

bhaskar@bhaskar-laptop_18:50:14_Fri Nov 05:~> find . -inum 655109 -exec rm -i {} \;
rm: remove regular empty file `./-hey'? Y



Hope this will help .

Cheers!
Bhaskar

Sunday, October 31, 2010

Rsync : A handy tool to sync with

In this article I am going to show you some implication of rsync tool.It is a tool often used by the web masters and system administrator to sync with various number of host across the network.Now what is the utility of having rsync under your armory? The advantage is quite useful.Here are few:

** It can sync filesystem across the network

** It can only sync the updated version the filesystem then the whole tree.

** It is very useful to copy the entire web site ported to new host or hosts.

** Rsync can do a various job related to backup procedure.

support for copying links, devices, owners, groups, and permissions

** exclude and exclude-from options similar to GNU tar

** a CVS exclude mode for ignoring the same files that CVS would ignore

** can use any transparent remote shell, including ssh or rsh

** does not require super-user privileges

** pipelining of file transfers to minimize latency costs

** support for anonymous or authenticated rsync daemons (ideal for mirroring)

Above stated advantages are name a few.Kindly look into the manual page of it.So,now I have four different partition and and I want to sync a particualr dir with all partiotn with a specific application running on all the OSes.

The idea is to get it sync; because I want the information to be indentical across all the partitions(same can be applied to different hosts too over the network!!).

How does it work?

You must set up one machine or another of a pair to be an "rsync server" by running rsync in a daemon mode ("rsync --daemon" at the commandline) and setting up a short, easy configuration file (/etc/rsyncd.conf). Below I'll detail a sample configuration file. The options are readily understood, few in number -- yet quite powerful.

Any number of machines with rsync installed may then synchronize to and/or from the machine running the rsync daemon. You can use this to make backups, mirror filesystems, distribute files or any number of similar operations. Through the use of the "rsync algorithm" which transfers only the diffs between files (similar to a patch file) and then compressing them -- you are left with a very efficient system.

For those of you new to secure shell ("ssh" for short), you should be using it! There's a very useful and quite thourough Getting Started with SSH document available. You may also want to visit the Secure Shell Web Site. Or, just hit the Master FTP Site in Finland and snag it for yourself. It provides a secure, encrypted "pipe" for your network traffic. You should be using it instead of telnet, rsh or rlogin and use the replacement "scp" command instead of "rcp."

Setting up a Server

You must set up a configuration file on the machine meant to be a server and run the rsync binary in daemon mode. Even your rsync client machines can run rsync in daemon mode for two-way transfers. You can do this automatically for each connection via the inet daemon or at the commandline in standalone mode to leave it running in the background for often repeated rsyncs. .Plus there is a CGI script that folks fire off frequently during the day for immediate updating of content. This is a lot of rsync calls! If you start off the rsync daemon through your inet daemon, then you incur much more overhead with each rsync call. You basically restart the rsync daemon for every connection your server machine gets! It's the same reasoning as starting Apache in standalone mode rather than through the inet daemon. It's quicker and more efficient to start rsync in standalone mode if you anticipate a lot of rsync traffic. Otherwise, for the occasional transfer follow the procedure to fire off rsync via the inet daemon. This way the rsync daemon, as small as it is, doesn't sit in memory if you only use it once a day or whatever. Your call.

Below is a sample rsync configuration file. It is placed in your /etc directory as rsyncd.conf.


motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock

[simple_path_name]
path = /rsync_files_here
comment = My Very Own Rsync Server
uid = nobody
gid = nobody
read only = no
list = yes
auth users = username
secrets file = /etc/rsyncd.scrt


Various options that you would modify right from the start are the areas in italics in the sample above. I'll start at the top, line by line, and go through what you should pay attention to. What the sample above does is setup a single "path" for rsync transfers to that machine.

Starting at the top are four lines specifying files and their paths for rsync running in daemon mode. The first is a "message of the day" (motd) file like you would use for an FTP server. This file's contents get displayed when clients connect to this machine. Use it as a welcome, warning or simply identification. The next line specifies a log file to send diagnostic and norml run-time messages to. The PID file contains the "process ID" (PID) number of the running rsync daemon. A lock file is used to ensure that things run smoothly. These options are global to the rsync daemon.

The next block of lines is specific to a "path" that rsync uses. The options contained therein have effect only within the block (they're local, not global options). Start with the "path" name. It's somewhat confusing that rsync uses the term "path" -- as it's not necessarily a full pathname. It serves as an "rsync area nickname" of sorts. It's a short, easy to remember (and type!) name that you assign to a try filesystem path with all the options you specify. Here are the things you need to set up first and foremost:

* path - this is the actual filesystem path to where the files are rsync'ed from and/or to.

* comment - a short, descriptive explanation of what and where the path points to for listings.

* auth users - you really should put this in to restrict access to only a pre-defined user that you specify in the following secrets file - does not have to be a valid system user.

* secrets file - the file containing plaintext key/value pairs of usernames and passwords.

One thing you should seriously consider is the "hosts allow" and "hosts deny" options for your path. Enter the IPs or hostnames that you wish to specifically allow or deny! If you don't do this, or at least use the "auth users" option, then basically that area of your filesystem is wide open to the world by anyone using rsync! Something I seriously think you should avoid...

Check the rsyncd.conf man page with "man rsyncd.conf" and read it very carefully where security options are concerned. You don't want just anyone to come in and rsync up an empty directory with the "--delete" option, now do you?

The other options are all explained in the man page for rsyncd.conf. Basically, the above options specify that the files are chmod'ed to uid/gid, the filesystem path is read/write and that the rsync path shows up in rsync listings. The rsync secrets file I keep in /etc/ along with the configuration and motd files, and I prefix them with "rsyncd." to keep them together.


For that reason I have mounted a partition which holds the updated version of the file and sync with others from that partition.

Say my Gentoo partition is updated and I want to update Arch,Fedora and Debian with that...so I have mouted all of them in different designated dir under the / .

Here is how I can sync that perticular file :


bhaskar@bhaskar-laptop_06:55:11_Sun Oct 31:/srv/http/dokuwiki> sudo /usr/bin/rsync -avrP data/ /Fedora/var/www/html/dokuwiki/


I will update the output of it once it finished.With rsync the trailing slash (/) has a big role to play.It signifies that you want to copy all the contents of that dir instead of the dir.Without the trailing slash rsync will copy the entire directory.Now some explanation about the flags I have passed with the rsync. Here is the meaning of those;


a ------> It says that in the format of archive

v -------> verbose mode

r --------> recursive mode

P ---------> progress mode

It has many other useful options with deal with.Kindly look into the man pages for more details.But when you sync over the network you must use it over the ssh so the tunnel get secured during transfer.It has "-e" option which will allow you to pass an ssh option with it.

Resources:
1) http://troy.jdmz.net/rsync/index.html

2) http://www.netbits.us/docs/stunnel_rsync.html

3) http://www.linux-mag.com/id/7888/1/
Hope this will help.

Cheers!
Bhaskar