Monday, March 15, 2010

Samba discussed in detail

Samba Overview
Samba is an application that allows a Linux or UNIX host to act as a file server for Windows systems and Windows systems can access UNIX filesystems and printers using their native Windows networking. We'll demonstrate a Linux system mounting a Windows drive and a Windows system mapping a Linux drive in this section.

Samba provides its file-sharing functionality using Server Message Block (SMB) protocol. SMB runs on top of TCP/IP. In our example in this section, both the Windows system and UNIX system are running TCP/IP and SMB. These provide all of the technology that is required to establish file sharing between the two systems.

At the time of this writing Samba contains the functionality just mentioned: file-sharing, printer sharing, and advanced user access control of files. There are many advancements taking place with Samba and other software provided under GNU Public License (GPL) as free software. Because the software is free, many people have access to it and spend time enhancing the software. For this reason, you may find that additional functionality is included in Samba and other such software.

smb.conf Setup

Because Samba is supplied on the Red Hat Linux CD-ROM, we'll walk through a simple Samba setup using Red Hat Linux. When installing Red Hat Linux, you can select the software packages you wish to load, as you can on most all UNIX variants. If you did not load Samba at the time you originally loaded the operating system, you can use a graphical RPM tool or rpm from the command line to load Samba or any other software.

The configuration file for Samba is /etc/samba/smb.conf. The smb.conf file has all Samba-related setup information in it. For our simple Samba setup in this chapter we need to have only a few lines in the file setup. We need to have a few Global Settings and Share Definitions in order to achieve our file system sharing between the Windows and Linux systems. The following are three select sections from smb.conf that were modified for our example in this section:

# workgroup = NT-Domain-Name or Workgroup-Name
workgroup = DEVENV

encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd

[homes]
comment = Home Directories
browseable = yes
writable = yes
valid users = %S
create mode = 0664
directory mode = 0775

We have a workgroup of DEVENV specified.

We want our passwords to be encrypted and we'll use the file /etc/samba/smbpasswd for these encrypted passwords. We'll have a user on both the Windows and Linux systems with the same name.

We have some information related to our Share Definitions, such as making the Home Directories browseable.

We made only these three modifications to the smb.conf file; however, next we'll run a Samba utility called testparm. This utility will check our /etc/smb.conf file for errors. This utility produces a very long output which I won't include here, but you'll want to run this and check for any warnings or errors it produces.

# testparm smb.conf

Load smb config files from smb.conf
Processing section "[homes]"
Processing section "[printers]"
Loaded services file OK.
Press enter to see a dump of your service definitions
# Global parameters
[global]
coding system =
client code page = 850
code page directory = /usr/share/samba/codepages
workgroup = DEVENV
netbios name =
netbios aliases =
netbios scope =
server string = Samba Server
interfaces =
bind interfaces only = No
security = USER
encrypt passwords = Yes
update encrypted = No
allow trusted domains = Yes
hosts equiv =
min passwd length = 5
map to guest = Never
null passwords = No
obey pam restrictions = Yes
password server =
smb passwd file = /etc/samba/smbpasswd
.
.
.

There were not warnings or errors produced from having run testparm so we'll proceed to the next step

User Setup
We now need to create a user on both the Linux and Windows systems that can be used for our Samba-related work. It may already be that you have suitable users on your system. For the purposes of this demonstration we'll create a user on both systems.

On the Linux system we can use the useradd program from the command line or User Manager graphical program (Programs-System-User Manager) to add the user. The user will appear in the /etc/passwd file after they have been added. We'll then issue the following command to add the encrypted user passwd to the /etc/samba/smbpasswd file:

# smbpasswd -a linuxconnect

linuxconnect is the name of the user we created for this example. You can view the smbpasswd file to see the entry for your user.

This same user was created on the Windows system.

Samba Startup
You can start Samba daemons every time the system boots or start them at the command line. The following commands show starting the daemons at the command line and then viewing them:

# /sbin/service smb start

Starting SMB services: [ OK ]
Starting NMB services: [ OK ]


# ps -ef | grep mbd
root 10828 1 0 16:59 ? 00:00:00 smbd -D
root 10833 1 0 16:59 ? 00:00:00 nmbd -D
#

We started the daemons with /sbin/service smb start and check to see our two daemons running with ps. Should you make a change to your Samba setup and wish to restart the daemons, you could use /sbin/service smb restart.

The smbd server daemon provides the file and print services to SMB clients, such as Windows systems. SMB stands for "Server Message Block" and is defined as a network protocol for sharing files, printers, serial ports, and communications abstractions such as named pipes and mail slots between computers.

The nmbd server daemon allows for NetBIOS over IP name service requests over a network, like those produced by SMB/CIFS clients such as Windows systems. We have now performed all of the basic setup required to proceed with mounting disks


Mapping a Windows Drive to a Linux Directory
Now we can both browse the Linux system from Windows as well as mount a specific drive directory of the Linux system on our Windows system. Now we specify the Linux system and directory we will mount as F: on the Windows system:

We specified the path of \\linuxdev\linuxconnect to mount on the Windows system drive F:. This is the hostname (linuxdev) and the username (linuxconnect). The system knows automatically to go to the home directory for linuxconnect and mounts that directory as F: for us on the Windows system

Let's now get the overall status of the Samba setup with the smbclient utility on our Linux system, as shown in the following listing:

# su - linuxconnect
$ smbclient -L linuxdev

added interface ip=192.168.1.102 bcast=192.168.1.255 nmask=255.255.255.0

Domain=[DEVENV] OS=[Unix] Server=[Samba 2.2.3a]

Sharename Type Comment
--------- ---- -------
homes Disk Home Directories
IPC$ IPC IPC Service (Samba Server)
ADMIN$ Disk IPC Service (Samba Server)
linuxconnect Disk Home Directories

Server Comment
--------- -------
LINUXDEV Samba Server

Workgroup Master
--------- -------
ATLANTA2 F4457MXP
DEVENV LINUXDEV

Before issuing the smbclient command we changed user to linuxconnect and then issued the command.

This utility produces a useful summary of the Samba setup, including the share linuxconnect we set up, the Samba server for our example, and other useful information

Find command in detail

Find command
Commonly used operators or options:

-atime n

Find files that were accessed n days ago. +n finds files accessed greater than n days ago and -n will find files accessed less than n days ago.

eg: We all have old files on our systems and in our home directories that have not been accessed in a long time. To find files in a home directory that have not been accessed in the last 200 days, you would issue the following command:

# find . -atime +200 -print

-ctime n

Find files in which the inode was modified n days ago. +n finds files in which the inode was modified greater than n days ago and -n will find files in which the inode modified less than n days ago.

-exec command

Execute command.

-group name

Find files belonging to the given group name where name can also be the group ID number.

-mount

Do not descend directories on other file systems (not available on all UNIX variants.)

-mtime n

Find files that were modified n days ago. +n finds files modified greater than n days ago and -n will find files modified less than n days ago.

-newer file

File was modified more recently than file.

eg: to find and remove all newer modified files
#find . ! -newer "almdmst001_30062009234031.htm" -exec rm -rf {} \;

-name pattern

Look for file name of pattern.

-ok command

Check to see that it is okay to execute command before doing so. This is similar to -exec except that you are prompted for permission.

-perm mode

Find files with the specified access mode. You would supply the access mode in octal.

-print

Print the current file name to standard output.

-type t

File has a type of t, such as d for directory and f for file.

eg:You may want to perform a find operation to produce a list of files only and not include directories in the operation. The following find is similar to what we performed earlier, but this time it produces a list of files only. This is achieved by specifying that we are looking for type f for files:

# find /home -type f -print

-size n

Find files with a size of n blocks. A block is usually 512 bytes. Using +n will find files greater than n blocks, nc will find files n characters in size and +nc will find files greater than n characters in size.

eg:we can search for all files on the system greater than 500,000 characters in size with the find command below:

# find / -size +500000c -print

-user uname

File is owned by uname.

Multiple Criteria:

-a to and two operators (operator1 -a operator2)

-o to or two operators (operator1 -o operator2)

! to specify that the operator not be matched (!operator)

\( expression )\ to specify that this expression be evaluated before others to specify preference.

Sunday, March 14, 2010

Mailing Services

Mailers are a set of UNIX® commands that provide command-line interfaces for users
to send and receive messages over the network. These interfaces, which are generally
referred to as Mail User Agents (MUA), communicate with a Mail Transport Agent
(MTA) to send mail messages to the appropriate destination, and receive messages
destined to the end user’s mailbox.

An MUA is a program that allows users to compose and read electronic mail messages.
The MUA provides an interface between the user and the MTA. An outgoing mail is
eventually delivered to an MTA for delivery, and the incoming messages are collected
from the MTA.

An MTA is a program that is responsible for delivering electronic mail messages. Upon
receiving a message from an MUA or another MTA, an MTA stores the message locally,
analyzes the recipients, and either delivers the message (for local addresses) or forwards
the message to another MTA for routing. In either case, the MTA can edit and add to
the message headers.

HP-UX systems use the Sendmail MTA and the elm, mail, and mailx MUAs.

Mailx Examples

echo "this is just for testing" | mailx -s"test" abc@yohoo.com

for files:

mailx -s "subject" recipient < file.txt


Sending Mail to a Local User

To check your local mailer or user agent, send a mail message to a local user (for
example, joe) on your system:

date | mailx -s "Local sendmail Test" joe

This must result in a message similar to the following being sent to user joe:
From joe Wed Aug 6 09:18 MDT 2002
Received: by node2; Wed, 6 Aug 02 09:18:53 mdt
Date: Wed, 6 Aug 02 09:18:53 mdt
From: Joe User
Return-Path:
To: joe
Subject: Local sendmail Test
Wed Aug 6 09:18:49 MDT 2002

An entry in your /var/adm/syslog/mail.log file must have been logged for the
local message transaction.

Replacing root mirror disk

Replacing root mirror disk

1. vgcfgrestore -n /dev/vg00 /dev/rdsk/c2t1d0 (restores LVM config from vg00 to c2t1d0 ie new disk)

2. lvlnboot –v ( prepares the LV to be root volume)

3. vgchange -a y /dev/vg00

4. vgsync /dev/vg00 ( synchronize the disk )

5. check whether all LV’s synchronized command: lvdisplay –v /dev/vg00/lvolx | grep stale | wc –l

6. Reboot the server and boot with the root mirrored disk.