Monday, March 5, 2012

File System Commands

File System Commands

  • Linux look at everything as a file. Linux file system will have tens of thousands of files. If you write a program you add one more file to the system. When you compile it you are adding at least two more.

  • Linux file is a storehouse of information. It is simply a sequence of charaters. linux places no restriction on the structure of the file. A file contains exactly those bytes that you out in to it, be it a source program executable code or anything else. It neither contains it's own size not it's attributes. It doesn't contain it's own name.

  • Although everything is treated as a file by linux it's still divided files into various categories:

                     Ordinary files, device files, directory files etc.

Commands:

pwd: Checking current directory:

  • When you log in you are placed in a specific directory of the file system. This directory is known as your current directory. At any time you should be able to know what your current directory. At any time, you should be able to know what your current directory is. For this we have to use the "pwd" command.

$pwd
/usr/ben

cd: changing directories:

  • We can move around in the file system using cd command. It changes the current directory to the directory specified as the argument. For example:


$pwd
/user/username
$cd progs
$pwd
/user/username/progs

  • The command cd progs means change your subdirectory to progs under the current directory. If we use absolute pathname that also the effect will be the same. You can use like this also
cd /user/username/progs

If we want to switch to the /bin  directory where most of the Unix/Linux commands are kept in that case we have to use the absolute pathname.
If we use cd without ant argument then it reverts to the home directory.

mkdir: Making Directories:

  • We can create directories with mkdir command. This command is followed by the named of the directories to create. If we want to make the directory by the name patch.

$mkdir patch

We can create number of sub directories in a single shot.

$mkdir one two three

Unix/Linux systems lets we create directory chain with just one command. For example:


$mkdir foo foo/one foo/two

This command creates three subdirectories- foo & two subdirectories under foo.
But we can't enter like this-

$mkdir foo/one foo/two foo

This command failed to create two subdirectories one & two but still creates foo
directory.


rmdir: Removing Directories:

  • We can remove directories with rmdir command. For example:

$rmdir patch
Like mkdir, rmdir can also delete more than one directory in a single shot. For example:

$rmdir one two tree
Also the tree directories & subdirectories that we just prepared using mkdir can be removed by using rmdir with reverse set of arguments.

$ rmdir foo/one foo/two foo

But we can't enter like this.
$rmdir foo foo/one foo/two

In this case, rmdir will silently delete the lowest levels of directories one & two. You should remember the following rules while deleting the directories.

  • "you can't delete the directory unless it is empty. In this case foo directory can't be removed  because of the existence of the directories one & two.

  • You can't remove a subdirectory unless you are placed in a directory, which is hierarchically above the one you have chosen to remove.

To understand this look at the following example.

$cd progs
$pwd
/user/useraname/progs
$rmdir progs
rmdir:progs:Directory does not exit.

To remove this directory we must position ourselves in the directory above progs that is username & remove it from there.

$cd /user/username
$pwd
/user/username
$rmdir progs

The mkdir and rmdir commands work with only those directories, which are owned by the user.

ls: Listing Files:

This command is used to list all the files in the current directory.

$ls

We can see here there is a complete list of filenames in the current directory. Arranged in ASCII collating sequence with one filename in each line.
If you want a particular file then just use ls with particular filename.

$ls patch
patch

-x Option:Output In Multiple columns:
When we have several files then it is better to display the filename in multiple columns. So we need the -x option to produce the multi-columnar output.
-F option: Identifying Directories & Executables:
With the help of ls command we got only the filenames, but we didn't know how many of them are directories & executable files. To get this -F option should be used.

$ls -F

Note that the  two symbols that  tag some of the filenames the * indicates the file containing the executable code & the / refers to a directory.

-a Option:Showing Hidden Files:

ls command doesn't show all the files in a directory. Some of files are hidden files in every directory. This option lists all the files even hidden files also.

All these files beginning with a '.' are normally not listed out only with ls.

-r Option: Reversing the sort order:

We can reverse the order of the presentation of the list with the -r option. The sorting is done in the reverse ASCII collating order.

$ls -r

The ls command will work differently if we give the two directory names with it. $ls directory1 directory2
Here is the list of important option:


Options Description
-x Display multi-columnar output
-r Sorts files in reverse order
-R Recursive listing of all files in subdirectories
-F Makes executables with * & directories with /
-a Shows all files including hidden ones
-i Shows inode number of files
-l Long listing showing seven attributes of flies
-d Force listing of directories
-t Sorts files by modification time
-u Sorts files by access time
 
 cat : Displaying and Creating Files:
cat command is generally used to display the contents of a file.
$cat filename
 cat command also accepts more than one filenames
$cat file1 file2
 The contents of second file are shown immediately after the contents of first file. cat is normally used to display the text files only.
Using cat to create file:
cat is used for  creating files. Look at the following examples:
$cat>one
This command shows the inserting of data into the files. ( Ctrl -d)
$ prompt returns
When we terminate the command line after pressing the enter key the prompt vanishes & now waits for input the user side. Finally press the control-d to signify the end of data input.

cp: Copying of files:
Copy the contents of one file to another with the cp command.
syntax
cp [options] old_filename new_filename
you now have two copies of the file, each with identical contents. They are completely independent of each other and you can edit and modify either as needed. They each have their own inode, data blocks and directory table entries.

We can also copy files to another directory. For example
cp one progs/two
cp can also be used to copy more than one file in a single shot. In that case the last filename must be a directory. For example : to copy files one, two, tree to the progs directory we have to write.
$cp one two tree progs
To work this command it is necessary that progs directory should be there.
you can also use * metacharacter if the names having same starting characters. For example: if filename are page1, page2, page3.
cp page* progs

Common Options
-i : interactive ( prompt and wait for confirmation before proceeding)
$cp -i one two
cp:overwrite two?y/n
-r: recursively copy a directory
It is possible to copy entire directory structure with this option. For example the following command copies all files & subdirectories from progs to newprogs.
cp -r progs newprogs

rm: Deleting files:
Remove a file with the rm, remove command.
syntax
rm [option] filename
common options
-i : interactive ( prompt and wait for confirmation before proceeding )
-r : recursively remove a directory, first removing the files and 
      subdirectories beneath it.
-f : don't prompt for confirmation (overrides -i)

Examples:
$rm old_filename
A listing of the directory will now show that the file no longer exists. Actually all you've done is to remove the directory table entry and mark the inode as unused. The file contents are still on the disk, but the system now has no way of identifying those data blocks with a file name. There is no command to "unremove" a file that have been removed in this way. For this reason many novice users alias their remove command to be "rm -i" where the -i option prompts them to answer yes or no before the file is removed.
rm dosen't normally remove directory but removes the files from it. You can remove two files from foo directory without having to "cd" to it.
$rm foo/one/ foo/two
sometimes it is required to delete all the files of directory then we can use the * metacharacter which represents all files. For example:
$rm *

mv: Renaming Files:
Rename a file with the move command, mv.
Syntax:
mv [option] old_filename new_filename

Common Options:
-i interactive (prompt and wait for confirmation before preceeding)
-f don't prompt even when copying over and existing target file ( overrides -i )
Example:
$mv old_filename new_filename
You now have a file called new_filename and the file old_filename is gone. Actually all you've done is to update the directory table entry to give the file a new name. The contents of the file remain where they were.
mv can also be used to rename a directory.

more:Paging Output:
If the file too large to display it's contents on screen, then the contents will scroll off the screen when we view it with cat. So a pager is required more allows the user to view a file one screen at a time. To view the contents of a file page1 use the following command with the filename.
$more page1
You will see the contents on the screen one page at a time. At the bottom of the screen, you will see the filename with the percentage of file content that has been viewed.
more command also contains some internal commands-
q- this command is used to exit more.
f- to scroll forward one screen.
b- to scroll backward one screen.
to move even slowly only one line at a time use, j key for scrolling.
forward and k for scrolling backward.
we can use more with multiple filenames.
more page1 page2 page3
you will first see the contents of the first file preceded by it's name after that the message "page1:ENDS(next file: page2)" and then the contents of the next file. In this way it display the contents of all the files. In between we can switch to previous or next files also using :n or :p for next and previous voyage.

lp (Line Printing): Printing A File:
Users are not allowed to directly access the  printer. But users can spool ( or line up) a job with others in a print queue. With spooling one can orderly print the jobs relieve the user from the necessity of administering the usage of print resources. The spooling facility is provided by the lp command. Take a look at following example:
$lp page1
request id is pr1-100(1 file )
This command will print a single copy of first page. This command also gives the request id. It is the combination of printer name & job number.
If there are more than one printer in a system, we have to use the -d option with the printer name if the printer name is dotmatrix.
$lp -ddotmatrix page1
The another option we can use with lp is -t ( title ) followed by the title string. this command prints the title on the first page.
$lp -t "first page" page1
We can cancel our jobs with cancel command which requires the request id of the job as an argument.
$ cancel pr1-100

file: To know the file types:
There are three of files. i.e. ordinary files directory files & device files. A regular file may contain simple text a C program or executable file. This file command is used to determine the type of file.
$file filename.lst
filename.lst:       English text
This command you can use with more filename also. We can apply this command to all the files in the progs directory. Just look at the following example ( * to indicate all the files )
$file /proc/*

wc: Line, Words and Character Count:
This command counts lines, words and characters depending on the options used. It takes one or more file name as an argument. Before you use wc command take a look at the following example

$create a file type some lines.
$ cat > filename 
$wc filename
This command offers three option to make specific count. This -l counts only number of lines, -w counts number of words and -c counts number of characters.
$wc -l filename
$wc -w filename
$wc -c filename
we can use this command with multiple file names, wc produces a separate line for each file.
$ wc file1 file2 file3


split: Splitting a file into multiple files:

Some file are so large that some times we found difficulties in editing them. So there's a need to split them. The split command breaks up its input into several equi-line segments and all these segments are created as separate file in  the current directory. Split by default break up a file into 1000 line pieces.
$split file1
This command creates a group of files xaa, xab, xac like this up to xzz. If the file is not large enough to occupy 1000 line you can override this default figure of 1000 by specifying the size.
$split -101 filename
Each file will contain 101 lines.

cmp: Comparing Two files:
Some times two files are exactly identical to each other, in such cases you can delete one of them. There are three commands to do this comparison one of them is cmp command. this command requires two file names as an argument.
$cmp file1 file2
This command compares the two files byte by byte and location of the first mismatch gives on the screen. The -l option gives a detailed list of byte number and differing bytes in octal for each character, that differs in both files.
$cmp -l file1 file2
If the two files are identical the cmp does not display many message but it simple returns the $ prompt.
diff: Differences in files:
The diff command compares two files, directories, etc and reports all differences between the two. It deals only with ASCII files. It's output format is designed to report the changes necessary to convert the first file into the second.
Syntax:
diff [option] file1 file2
Common Options
-b ignore trailing blanks
-i ignore the case of letters
-w ignore and characters
-e produce and output formated for use with the editor, ed
-r apply diff recursively through common sub-directories
Examples:
For the file1 and file2 files, the difference between them:
 Note that the output lists the differences as well as in which file the difference exists.
Lines in the first file are preceded by "<", and those in the second file are preceded by ">".

File Permissions:
Each file, directory and executable has permission set for who can rad, write, and/or execute it. To find the permissions assigned to a file, the ls command with the -l option should be used. Also using the -g option with "ls -l" will help when it is necessary to know the group for which the permissions are set ( BSD only ).
When using the "ls -lg" command on a file ( ls -l on sysV), the output will appear as follows.
-rwx-r-x--- user unixgroup size month nn hh:mm filename
The are above designated by letters and dashes ( -rwx-r-x---) is the area showing the file type and permissions. Therefore, a permission string for example of -rwx-r-x--- allows the use ( owner ) of the read, write and execute it; those in the unixgroup of the file can rad and execute it; others cannot access it at all.

Chmod - Change File Permissions:
The command to change permissions on an item ( file, directory, etc) is chmod ( changes mode). The syntax involves using the command with three digits ( representing the user ( owner, u) permission, the group (g) permissions, and other (o) user's permissions) followed by the argument (which may be a file name or list of files and directories). Or by using symbolic representation for the permissions and who they apply to.
Each of the permission types is represented by either a numeric equivalent:
read=4, write=2, execute=1
or single letter:
read-=r, write=w, execute=x
A permission of 4 or r would specify read permissions. If the permission desired are read and write, the 4 (representing rad) and the 2 (representing write) are added together to make a permission of 6. Therefore, a permission setting of 6 would allow read and write permissions.
Alternatively you could use symbolic notation which uses the one letter representation for who and for the permissions and an operator, where the operator can be:
+ add permissions
- remove permissions
= set permissions
So to set read and write the owner we could use "u=rw" in symbolic notation.
Syntax:
$ chmod nnn [argument list] numeric mode
$ chmod [ who]op[prem] [argument list] symbolic mode 
Where nnn are the three numbers representing user, group and other permissions, who is any u, g, o or a (all) and perm is any of r, w, x . In symbolic natation you can separate permission specifications by commas as shown in the example below.
Common Options:
-f force (no error message is generated if the change is unsucessful)
-R recursively descend through the directory structure and change the modes.

Example:
If the permission desired for file1 is user: read, write, execute, group: read, execute, other: rad, execute the command to use would be
$ chmod 755 file2 or chmod u=rwx,go=rx file1
Reminder: When giving permissions to group and other to use a file, it is necessary to allow a least execute permission to the directories for the path in which the file is located. The easiest way to do this is to be in the directory for which permissions need to be granted.
chmod 7111. or chmod u=rw,+x. or chmod u=rwx.go=x.
where the dot (.) indicates this directory.

Shell
Shell is command interpreter that execute commands. A Unix shell is both a command interpreter, which provides the user interface to the rich set of unix utilities, and a programming language allowing these utilities to be combined. Files containing commands can be created and become commands themselves. These new commands have the same status as system command in directories like '/bin', allowing users or groups to establish custom environments.
A shell allows execution of unix command both synchronously and asynchronously. The shell waits for synchronous commands to complete before accepting more input; asynchronous commands continue to execute in parallel with the shell while it reads and executes additional commands. The redirection construct permit fine-grained control of the input and output of those commands and the shell allows control over the contents of their environment. Unix shells also provide a small set of built in commands ( builtins ) implementing functionality impossible ( e.g. cd, break, continue and exec ), or inconvenient ( history, getopts, kill or pwd for example ) to obtain via separate utilities. Shells may be used interactively or non-interactively they accept input typed from the keyboard or from a file.
While executing commands is essential most of the power ( and complexity ) of shells is due to their embedded programming languages. Like any high-level language, the shell provides variables flow control constructs, quoting and functions.
Shells have begun offering features geared specifically for interactive use rather than to augment the programming language. These interactive features include job control command line editing history and aliases.
Shell Operations:
The following is a brief description of the shell's operation when it reads and executes a command. Basically the shell does the following:
Reads it input from a file, from a string supplied as an argument to the '-c' invocation or from the user's terminal.
Breaks the input into words and operators, obeying the quoting rules. These tokens are separated by metacharacters. Alias expansion is performed by this step.
Parses the tokens into simple and compound commands.
Performs the various shell expansions, breaking the expanded tokens into lists of filenames and commands and arguments.
Performs any necessary redirections and removes the redirection operators and their operands from the argument list.
Executes the command.
Optionally waits for the command to complete and collects its exit status.

comments:
In a non-interactive shell or an interactive shell in which the interactive_comments option to the shops built in is enabled a word beginning with '#' causes that word and all remaining characters on that line to be ignored. An interactive shell without the interactive_comments option enable does not allow comments. The interactive_comments option is on by default in interactive shells.

Pipelines:
A pipeline is a sequence of simple commands separated by '|'. The formate for a pipeline is -
[time [-p]] [!] command1 [|command2..]
The output of each command in the pipeline is connected to the input of the next command. That is each command reads the previous command's output.

Pattern Matching : Wild cards:
Up to this point we used certain commands with more than one filename (e.g., page1 page2, page3) as arguments. Often you may require to enter a number of such filenames in the command line. To illustrate this look at the following examples:
$ls -l file1 file2 file3
Each filename has a common string viz., page.  But this command line requires lot of typing work & doesn't look good. Fortunately shell offers solution to this.
The * And ?
this * is known as metacharacter. this character matches any number of characters. When this character is appended to the string page the pattern page *  expands in to all files in which first four characters constitute to string page. The previous command line can now be shortened with this sequence.
$ ls -l file*
Now when shell encounters the above command line it looks for metacharacters & identifies the * immediately. It then matches all the files in the current directory with the pattern page start and replace the pattern with the list that matches the pattern. It then reconstructs the command line as below & passes it to the kernel for execution.
$ls -l file1 file2 file3
The next character is ? , which matches a single character. When used with the same string page (page?) the shell matches all five character filenames beginning with page. Placing another? at the end of this string creates the pattern page?? where page is followed by two characters. Look at the following example.
$ls -x file?

Pattern Matching
Any character that appears in a pattern other than the special pattern characters described below, matches itself. The NULL character may not occur in a pattern. The special pattern characters must be quoted if they are to be matched literally.
The special pattern characters have the following meanings:
* Matches any string including the null string.
? Matches any single character.
[...] Matches any one of the enclosed characters. A pair of characters separated by a minus sign denotes a range; any character lexically between those two character, inclusive is matched. If the first character following the `['is a ` !' or a `^' then any character not enclosed is matched. A `_' may be matched by including it as the first or last character in the set. A `}' may be matched by including it as the first character in the set. Within `[' and `]' , character classes can be specified using the syntax [:class:], where class is one of the following classes defined in the POSIX.2 standard:
alnum alpha ascii blank cntrl digit graph lower print punct space upper sdigit
A character class matches any character belonging to that class. Within `[' and `]', an equivalence class can be specified using the syntax [=c=], which matches all characters with the same collation weight ( as defined by the current locale ) as the character c. Within `[' and `]', the syntax [.symbol.] matches the collating symbol symbol.
If the extglob shell option is enable using the shopt built in, several extended pattern-matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a `|'. Composite patterns may be formed using one or more of the following sub-patterns:
? ( pattern-list)
         Matches zero or one occurrence of the given patterns.
* ( pattern-list)
        Matches zero or more occurrences of the given patterns.
+ ( pattern-list)
        Matches one or more occurrences of the given patterns.
@  ( pattern-list)
       Matches exactly one of the given patterns.
! ( pattern-list)
       Matches anything except one of the given patterns.

When Wild - Cards lose their meaning:
The metacharacters * and ? lose their meaning when used inside the class & are matched literally. Similarly - & ! also lose their significance when placed outside the class. Additionally ! loses it's meaning when placed anywhere but at the beginning of the class. The - loses it's meaning if it is not bounded properly on either side by a single character.
Matching the Dot:
The * doesn't match all the files beginning with a . (dot) or the / of a pathename. If you want to list all the hidden files in your directory having at least 3 characters after the dot, then the dot or the must be matched explicitly.
$ls -x .???*

When using rm with *:
We use these metacharacter to speed up our interaction with the system but there are great risks involved if you are not alert. When using shell metacharacters  especially the *, you could be totally at sea if instead of typing
$rm file*
Which removes all file. You inadvertently introduces space.
$rm file * ( space between page and * )
Even if there is not file named file in the current directory, and you get an error message to indicate that the command will still removed all files in this directory because of singular existence of *. This happens because shell rightly treats the * as a separate argument.
Escaping: The Backslash (\):
It is generally accepted principle that file names should not contain the shell meta characters. What happens if we do that imagine a file named page* created with the >.
Symbol:
$>file*    # you can create any empty file like this 

How do we remove this file without deleting other files. ( If we have other files named  file1, file2, file3). the shell uses another characters \(Backslash), to remove the special meaning of any metacharacter placed after it. Here the shell has to be told that the asterisk has to treated & matched literally, instead of being interpreted as metacharacter use the \ before * to solve  the problem.
$ ls -x file\*
file*
$ rm file\*
Escaping The < ENTER> Key:
When you enter a long chain of commands you can split the command line by hitting enter key. But only after the \ escapes this key.
$wc -l file1 \ ( Enter)
> file2 file3 ( Press Enter )


Quoting:
What happens when we enter a shell metacharacter with echo command as below:
$echo *
showing files and directories
 You simply see list of all files in the current directory. Why that happens? The shell uses the * meta character to match the files in the current directory. All files matched so you see all of them in the output. Suppose you intend to literally echo a * without permitting the shell to interfere. Escaping with a \, solves the problem.
$echo \*
There is another solution. When the argument to a command is enclosed in quotes the meaning of all special characters are turn off.
$echo '*' ( you can use double quotes also )

Quoting Preserves Spaces:
Whenever a shell finds contiguous spaces & tabs in the command line, it compresses them to a single space. Look at the following example:
$echo write one or two lines with so many space.
The above arguments to echo could have been preserved by escaping the space character, whenever it occurs at least twice.
$ echo dflfjdasl\ \ \sdafsda\ \ \sdfsad\ \    \sdfsad\.
In this situation quoting is recommended.
$echo "sdfklsajlfjsadl;"

grep: Searching For A Pattern:
grep is one of the most useful unix filter. It scans the file for a specific occurrence of a pattern, and displays the selected pattern the filenames where that pattern occurs or the line number in which they found. The syntax for it is as follows- grep option pattern filename (s)
Look at the following example
$ps -aux | gerp firefox
grep when unable to find the required pattern then it silently returns the prompt. Take a look at this -
$ grep production record1.lst
$-    #No production person found
It is generally safe to quote the pattern though always it is not required. Quoting is essential if the search string consist of more than one word. Try the following example -
$grep baiju damoder record.lst
gerp:can't open damodar
 gerp interprets damodar as a filename and so unable to open that file. but still searches the record1.lst and gives the result. To correct this problem you quote the pattern just like -
$ grep 'jiten' record1.lst
When we use grep with a series of string it interprets the first arguments as the pattern & the rest as filenames. It then displays along with the output.
$grep manager record1.lst record2.lst
grep options:

Option
Significance
-c
Displays count of number of occurances
-l
Displays list of filename only
-n
Display line number along with lines
-v
Displays all but lines matching expressions
-i
Ignores care for matching
-h
Omits filenamewhrn handling multiple files
-n
Display line & n lines above & below
 














Wednesday, February 29, 2012

User and Group Management

User and Group Management

Description:

Managing user accounts in linux is of paramount importance as users need an ID just to login to the system. Create, Delete and Change user attributes.

Introduction:

Linux being a multi-user, multitasking operating system, needs every user to possess a user name and a password. So to efficiently use linux we first need to know the process of creation of users and using the created users to logon and logout of the system.

We summaries a few points regarding user accounts.

  • Linux operating system is case sensitive. This imposes that we use commands in the lower case to get our work done. Command typed upper-case will throw errors.
  • Every on a Linux system needs a user account.
  • Every account has right ans privileges that very depending on the command and the directory. 
  • Linux users are organized into groups.
  • In RHEL user accounts are organized in the '/etc/passwd' file.
  • Their passwords are made more secure by the use of the '/etc/shadow' file.
  • When creating a new account the default parameters are configured in the '/etc/login.defs' file.
  • Configuration files are stored in another directory from where the files are copied to the user's home directory while the user is created.

Introduction to files that relate to the users of a system:

/etc/passwd
  •  Linux users are classified into three types
  1. Administrative (root)
  2. Regular
  3. Service
  • The administrative root account is automatically created when you install linux which has administrative privileges for all services on your linux box.
  • Regular users have the necessary privileges to perform standard task on linux computer. They can access programs such as word processors, databases and web browsers. They can store files in their home directories only.
  • Services such as Apache, ftp, Squid, nail, games, audio etc. have their own individual service accounts.
  • each column in the '/etc/passwd' file is delimited by a colon(:)

Column
Function
Comment
1
Username
Login name of the account
2
Password
If this field contains an X, the encrypted password is stored in /etc/shadow
3
UserID
A numeric ID for the usr. Assigned by the OS
4
GroupID
A numeric ID for the default group of the user. Assigned by the OS
5
Extra Information
Commonly used for the user's ral name. Can be any comment on the account
6
Home directory
The path to the user's home directory
7
Defaulty shell
The shell the user sees after logging in
 
/etc/shadow

  • This is the file that holds the password information of the users of the machine.
  • It is a read-only file for the root and no permissions are afforded for anyone else. Hence it is more secure.
  • If you use standard command to create new users, basic information is also added to this file based on the defaults in the '/etc/login.def
Column
Function
Comment
1
Username
Login name
2
Password
The encrypted password. Blank if the user has no password. A * signifies a password has not been defined. If the useris disable from logging in to the system an ! Is displayed.
3
Number of days
Last time the password was chagned in days after january 1,1970
4
Minimum password life
You can't change the password for at least this amount of time in days.
5
Maximum password life
You have to change the password after this period of time in days
6
Warning period
You get a warning this name days before your password expires
7
Disable account
If you don't use your account this many days after your password expires, you can't log in
8
Account expiration
If you don't use your account by this date, you won't be able to log in. Maybe in yyyy-mm-dd format or in number of days after january 1,1970
 
/etc/skel

  • Users have a default set of configuration files and directories.
  • The default list of these files is located in the '/etc/skel' directory.
  • you can see the files by listing the hidden contents of the skel directory. 
  • All new users will get a copy of these  files in their home directories.

Files
Purpose
.bashrc
The basic bash cofiguration file. May include a reference to the general /etc/bashrc
.bash_logout
A file executed when you exit a bash shell. Can include commands appropriate for this purpose, such as clearing your screen
.bash_profile
Configures the bash start up environment. Appropriate place to add environment variables or to modify the directories in your PATH
.gnome*
Servral directories that include start up setting for the GNOME desktop environment. For example, details of desktop icons such as Trash are stored in .gnome-desktop/Trash
.gtkrc
Adds the bluecurve theme for the default Red Hat GUI
.kde
A dirctory that includes auto start setting for the K Desktop environment. Not copied to the users home directories if you haven't installed KDE in the computer.

/etc/login.defs

  • When you create a new user the basic parameters come from the /etc/login.defs configuration file.
  • The version included with RedHat Linux includes settings for
  1. Email directories
  2. Password directories
  3. UserID numbers
  4. GroupID numbers
  5. Creating a home directory 
Adding Users - Creating and management of user account :

Login/Logout, Shutting down, Restarting a System and using commands to add users 
  • To logon to the system you should enter username and password
login: username
password: **********

  •  To create a user
#useradd username ( Read man page for more controlled user creation )
#man useradd

  • To set the password for the newly created user
#passwd username

  • To log off the system and enter as a new user
#exit
  • To shut-down a system
#init 0
#shutdown -h now
#poweroff

  • To restart a system
#init 6
#shutdown -r now
#reboot

Editing the /etc/passwd file directly:

  • Open the /etc/passwd file for editing using a text editor.
# vim /etc/passwd
  • Start a new line. the easiest way to do this is by copying the applicable information from a current user.
  • Substitute the information of your choice to create the new user.
  • For example change the user name as testuser, UID as 1010, GID as 1010, full name as "This is a test user" ( less the quotes), /home/testuser as the home directory.
  • Save and Exit.
  • Open the /etc/shadow file for editing using a test editor.
# vim /etc/shadow

  • Create a new line by copying the applicable information from a current user.
  • Change the group name as testuser and GID as 1010.
  • Save and exit.
  • Set up your new user's home directory.
#mkdir -p /home/testuser

  • Give the new user access to his home directory.
# chown testuser:testuser /home/testuser

  • Assign a new password with passwd command
# su -testuser

  • Copy the basic initialization files which are normally stored in the /etc/skel directory.
#cp -r /etc/skel/ /home/testuser 
#cd /home/testuser
#mv /etc/skel/* .           ---------------------------> (ignore error message)
#mv /etc/skel/.* .
#rmdir skel

  • Change the Ownership of the files and directories copied to the home directory of the user.
#chown testuser:testuser /home/testuser /home/testuser
  • Logout from the user's account.
  • Assuming you're using the default shadow password suite, run the pwconv and grpconv commands.

Deleting user account by deleting entries in the files:

  1. Delete the user's entry from the /etc/passed file.
  2. Delete the user's entry from the /etc/group file.
  3. Delete the user's entry from the /etc/shadow file.
  4. Delete the user's entry from the /etc/gshadow file.
  5. Delete the user's home directory after saving the files you need.

Commands:
Useradd -u 1010 -g 1010 -s /bin/bash -d /home/testuser -m testuser
#useradd username
#useradd -u UID username
#useradd -g GID username
#useradd -G username
#useradd -c username
#useradd -s username
#useradd -e username
#useradd -d username
#useradd -m username {to create the home directory if it does not exist}

Usermod -l -L -U:
usermod -l          {to change the user login name}
usermod -L         { to lock a user account}
usermod -U         {to unlock user accounts}

change:
chage  -m    { sets minimum life of password to days}
chage  -M    { sets maximum life of password to days}
chage  -I      {sets the number of days that an account can be
                                               inactive before it is locked}
chage -W     {sets an advance warning in says of an upcaming
                                              mandatory password change}
chage -l                    {list the current user password information. can be 
                                               used by regular users on their own accounts}

The Shadow password Suite:

  • The Shadow Password Suite features all of the commands related to managing Linux users and groups.
  • By default RedHat Linux uses this suite to provide additional security through encrypting passwords in the /etc/shadow and the /etc/gshadow files.
  • These files require commands to convert passwords to and from the companion /etc/passwd and the /etc/group configuration files.
  • These encrypted password files have more restrictive permissions than /etc/passwd or /etc/group; only the root user is allowed to only view these files and they are not writable by default.
 Converting User Passwords:

  • Two commands are associated with converting user password in the shadow password suite.
pwconv
pwunconv

pwconv:
  • Converts an existing /etc/passwd file. Passwords that currently exist in the /etc/passwd are replaced by a "x" the encrypted password, username, and the other relevant information are transferred to the /etc/shadow file.
  • If you've recently added new users by editing the /etc/passwd file in a text editor you must run this command again to convert the passwords associated with any new users.
pwunconv:

  • Password are transferred back to the /etc/passwd, and the /etc/shadow file is deleted.
  • Be careful as this also deletes any password aging information.

/etc/group:

  • Every linux user is assigned to a group.
  • By default every user gets their own private group.
  • This file has four columns as follows
Column
Function
Comment
1
Group name
By default red hat users are members of a group with their username
2
Password
If you see and 'x' in this column, see /etc/gshadow for the actual encrypted password
3
GroupID
By default redhat users have a GID same as their UID
4
Members
Includes the usrnames of others that are the members of the group

/etc/gshadow:

  • The RHEl /etc/gshadow configuration file for the group is analogous to the /etc/shadow file for users.
  • It specifies an encrypted password for applicable group, as well as administrators with privileges for a specific group.
  • This file has four columns as follows
Column
Function
Comment
1
Group name
You can create additional groups.
2
Password
The encrypted group password, added with the gpasswd command.
3
Group Administrator
The user is allowed to manage users in that group.
4
Group Members
Includes the usernames that are the members of the same group.

Group Commands:
  • #groupadd -g GID
  • #groupadd -n
  • #groupdel
  • #groups < username>          {displays the group memberships that the  
                                                       user  has}
  • #id                                         { to get ID information}

Tuesday, February 28, 2012

RedHat Package Management

Red Hat Package Management

Description :

Every user of a linux system needs to install or remove software in his system. There are a few methods available by which one can install software into Red Hat Linux. One method is to user the source tarballs to install the packages into linux and the second method is to user per-compiled binaries into the system. These are usually called as RPM and in Debian it is call DPKG packages.
Red Hat package Management utility to install and remove packages from a Linux system.

Introduction:

Generally a package's name  will be in the following format.
packagename.version.release.architecture.rpm

Eg. firefox-4.0rc2.tar.bz2,firefox.9.0.0.1-0.1.mga1.x86_64.rpm

Redhat  Linux includes a tool name rpm to administer the software packages. Using rpm command you can:

  • Installing Packages
  • Upgrading Packages
  • Removing packages
  • Querying Packages
  • Removing Packages

Command Syntax: root@linux:~#rpm -I [option] package

Package is the complete name of the package to be installed. The options refine the installation process. The options are explained below.

-v                Turn on verbosity. Shows some useful information during the  
                   installation.
 -h               Print up to 50 hash marks (#) to illustrate the progress of the 
                   package installation.
 --force        Install the package even if it already is installed, install an older 
                   version or replace files already installed.
--nodeps     Do not perform dependency checks before installing or upgrading  
                   a package.
--test           Do not install the package or upgrade the database, just identify  
                   and display possible conflicts or dependency errors.

 In your installation CD-ROM RPMs are stored under REDHAT/RPMS directory. For installing software packages from the installation CD-ROM do the following steps.

Installing Packages:

  • Insert the CD-ROM in the drive mount the cdrom and select the package to install. Alternatively you can change your directory to the place where the RPMs have been downloaded.

#mount /dev/cdrom /mnt/cdrom or /media/cdrom
#cd /mnt/cdrom
#rpm -ivh firefox.9.0.0.1-0.1.mga1.x86_64.rpm

  • The next example shows the error generated by trying to install a package which is already installed. To work around we use the '--force' option.

#rpm -ivh firefox.9.0.0.1-0.1.mga1.x86_64.rpm
#rpm -ivh --force firefox.9.0.0.1-0.1.mga1.x86_64.rpm

Upgrading Packages:

The option for upgrading existing RPMs comes in 2 flavour , -U for gpgrade and -F for freshen. Upgrade will install the package even if an earlier version is not currently installed, but freshening package installs only if an earlier version is currently installed.


#rpm -Uvh firefox.9.0.0.1-0.1.mga1.x86_64.rpm

Note: You can use a program called 'alien' to convert between packages like rpm, dpkg, stampede sle and slackware tgz file formats.

The following table illustrates methods of using the RedHat Package Manager.

 
Question
RPM Command
How do I install a new package or upgrade it if it already exists?
#rpm -Uvh package.rpm


If I have a diretory containing updated packages, how do I insatll the only the ones that are currently in my system?
#rpm -Fvh *.rpm
How do I delete an insallted packase from my computer?
#rpm -e package
How do I see a list of all installed packages on my computer
#rpm -qa | less


I don't know what a certain installed package does. How can I get it to tell me about itself?
#rpm -qi package
How do I ask what files were installed by a package?
#rpm -ql package
There's a file in my system called /apth/to/file. How can i find out which package installed it?
#rpm -qf /path/to/file
How do I find out which package installed /apth/to/file and how do I get information on that package and see the other file that were installed by the package
#rpm -qifl /path/to/file
I delete a few files by accident but I don't know what are they. Can RPM chow me which files in its database are now missing?
#rpm -Va
'#rpm -Va' is taking a log time. How do I just verify that a certain package is OK?
#rpm -Vv package
I've downloaded an RPM package containing source code. How do I make a binary RPM out of it and then install it?
#rpm -ivh package.src.rpm
#cd /usr/src/redhat/SPECS/
#rpmbuild -ba package.spec
#cd /usr/src/redhat/RPMS/i386
#rpm -ivh package.rpm
How do I compress and rebuild my computer's RPM database?
#rpm -rebuilddb

















Networking In Linux

Networking In Linux

Descriptions:

Any system if needed to connect to the Internet, would require the networking components configured. Linux offers various methods to control the network interfaces of a system which will be explored .
Linux provides excellent support for networking and configuration of the various options via the command line as well as built-in configuration tools.


Gathering network information and setting IP addresses:

  • The first step is to find the IP address and the currently active interfaces in the system that we are using. Use the command 'ifconfig' to get a list of all active interfaces in the system.
Use the same command with the -a switch to get a list of all interfaces.

#ifconfig

eth0      Link encap:Ethernet  HWaddr b8:ac:6f:b5:8a:3a 
          inet addr:10.112.18.76  Bcast:10.112.255.255  Mask:255.255.0.0
          inet6 addr: fe80::baac:6fff:feb5:8a3a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:110687304 errors:0 dropped:0 overruns:0 frame:0
          TX packets:84807708 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3862591144 (3.8 GB)  TX bytes:2051180865 (2.0 GB)
          Interrupt:18

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1098 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1098 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:610070 (610.0 KB)  TX bytes:610070 (610.0 KB)

  • We assign an IP address to the interface 'eth0' using the command line as follows :
#ifconfig eth0 192.168.1.1 netmask 255.255.255.0

we also check if the changes have taken place using the 'ifconfig' command. You may not give the subnet mask value if you want the default ones to be used.

#ifconfig eth0

  • However this assignment of the IP address is only a temporary one and will be lost upon the next system reboot or restart of the network services.

  • To prevent this from happening and the avoid the setting of the IP address for each session, edit the configuration file for the interface which is located in the '/etc/sysconfig/network-script' directory. The file will be called 'ifcfg-'. In  our example, the file will be called 'ifcfg-eth0'.

  • Edit the lines in the original file which is as follows:

DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=08:0027:27:57:52
ONBOOT=yes
TYPE=Ethernet

To read as follows



DEVICE=eth0
BOOTPROTO=static
HWADDR=08:0027:27:57:52
ONBOOT=yes
TYPE=Ethernet
IPADDR= 192.168.1.1 --------------------------------------> IP address
 NETMASK= 255.255.2555.0 ---------------------------> subnet mask

  • From the next boot onward the system will take the IP address that you designated.

Adding and Deleting gateway in Linux:

  • The IP address assigned so far would only allow for communication between system in the same subnet. To add support for communications to other subnets, we need to add gateways to the system.

  • We add default gateway to the system by using the 'route' command.
#route add default gw 192.168.1.254

  • We can add a dedicated route to a particular network or host by issuing the route command but with a few changes to the command used above.
#route add -net 10.0.0.0 netmask 255.255.255.0 gw 192.168.1.10
#route add -host 172.16.1.1 gw 192.168.1.11

  • To look at the current routing table in the kernel we use the same command but this time without any arguments. However we can use the '-n' switch which will give the output in the numeric format.
#route -n

  • To delete a route we use the 'route' command itself but with the 'del' option passed instead of the 'add'.
#route del -net 10.0.0.0 netmask 255.255.255.0

  • A look at the kernel routing table shows that the route to the 10.0.0.0/32 network no longer exists. 
#route -n

Using the 'system-config-network' tool:

  • Open a terminal and type 'system-config-netowrk'
  • In the monitor we will see network configuration tool Utility.
  • Select the interface whose properties you wish to change and click edit. A screen as shown on monitor.

  • Choose the properties of the interface as per your requirements.
  • To add route to the system click on the Route tab.
  • Click on 'Add' icon and you will configure IP address and Subnet Mask , Gateway.
  • Finally you can delete a route by selecting the route and then clicking 'Delete' in the 'Route' tab.



Disk Management in Linux

Disk Management in Linux

Descriptions:

Secondary storage forms the fundamental part of any computing infrastructure. System administrators are expected to utilize hard drives effectively to help users in optimizing  their productivity. Using command line tools to manage hard disks in linux.

Introduction:

Linux offers utilities to manage hard disks. Users may add, delete change partition types. Furthermore they can also implement software RIAD, LVM etc using command line utility.

Here are a few caveats regarding hard disks.
  • A disk drive requires a partition table.
  • The partition is the logical sequence of cylinders in the disk.
  • A cylinder represents all the sectors that can be read by all heads with on movement of the arm that contains all these heads.
  • Linux supports up to 16 partitions on any individual IDE or SCSI drive.
  • Primary partitions: 3 , Extended partition: 1, Logical partition:12


Hard Disk Overview:

Firstly we start off by inspecting the hard disk for its current set-up. Our aim now is to find the partitions and their types those are currently existing. All commands need to be executed as the 'root' user. Hard disks are detected in the location /dev/hda'n' ( for IDE drvies) or /dev/sda'n' ( for SATA/SCSI drives). The 'n' denotes the partition number in that hard drive. Primary partitions are numbered from 1-3 and extended partition is given the number 4. All logical partitions are given numbers 5 onwards. However, the conventions differ as per the distribution of linux that you are using.

The 'a' in the hda (or sda) is the location of the hard disk controller where the hard drive is connected. So for IDE drives, 'a' is the primary master channel, 'b' is the primary slave channel, 'c' is the secondary master channel, 'd' is the secondary slave channel. Accordingly the location where the hard disk gets read would change to either /dev/had, /dev/hdb , /dev/hdc, or /dev/hdd.

In my system that has 2 hard disks, a 500 GB primary master and a 1 TB primary slave, I execute the following commands. I have just added the 1 TB partition. So lets perform all our operation in this hard drive only.

#fdisk -l


Disk /dev/sda: 320.1 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000080


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      194560   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              25       38914   312373249    5  Extended
/dev/sda5              25         523     3998720   82  Linux swap / Solaris
/dev/sda6             523       38914   308373504   83  Linux

When I gave this command without specifying the device, I get a list of all hard drives and I get an informatory messages that the hard disk /dev/hdb has no valid partition table. Also the hard drives are recognized as IDE hard drives in slots 'a' and 'b'. To get details regarding only one hard drive, pass the location of the hard disk to the same command.

#fdisk -l /dev/hda

Lets analyses the output:

  • The command request the details of the hard disk attached to /dev/hda.
  • The output first gives the human-readable ( MB, GB etc.) size of the hard disk.
  • Next it gives the actual size of the hard disk in bytes.
  • Next are a few details on the number of heads, sectors and the total number of cylinders in the hard disk.
  • Then the details of the partitions are given. Each column is as follows.


Title
Explanation
Device
The absolute path to the partition
Boot
Specifies which partition is bootable. An asterisk in marked to designated this partition
Start
The starting cylinder of the partition
End
The last cylinder of the partition
Blocks
The number of blocks in that partition
Id
The file system id, a hexadecimal number to denore the file system in the partition
System
The type of the partition. A human-understandable format
 
Creation and Deletion of partitions :

As we have a 4 GB hard disk that does not have a partition table. We will create 2 partition in it.
  • We use the fdisk to create partition in the second hard drive.
#fdisk /dev/hdb

  • Pressing 'm' will display the help for you.

  • We create a new primary partitions occupying 6000 cylinders for the first one and the remaining for the second partition which will be an extended partition. Note: You can create a partition of a specific size that  you want. Just rad the option carefully. Pressing ENTER at any question will take the default value for that question, if there is any.
Command ( m for help): n

  • We look at the partition table by pressing 'p'

  • The changes we made so far only temporary and will be finalized to the disk only when you explicitly  order 'fdisk' to do so. Confirm changes using the 'w' option. The 'q' option will quit without saving changes.
Command (m for help): w

  • This creates the partition in the hard disk. But the changes are not yet read by the Operation System. The next step is no make the kernel re-read the partition in the hdb device.
# partprobe /dev/hdb

  • We next make the filesystem that linux can read in the partition hdb1.
#mkfs.ext3 /dev/hdb1 ( partition name )

  • Similarly we add a filesystem to the hdb2 partition as well
#mkfs.ext3 /dev/hdb2

  • The deletion of a partition can be accomplished by typing 'd' and corresponding number of the  partition which you want to delete when prompted for one.


 


Friday, February 24, 2012

SAMBA Server

SAMBA Server Configuration

Descriptions:

The presence of linux workstation in a network will invariable demand the need for allowing remote file access in between systems. Samba is a solution that is used to enable UNIX-Windows file sharing. Readers implements a samba server in the network so that other users of the LAN can leverage the functionalities of network file sharing.

Introduction:

  • Samba is a suite of programs running under UNIX-like operating systems that provide integration between unix and windows machines. Samba uses server Server Message Block ( SMB ) protocol which is the underlying protocol used in Microsoft Windows Networking.

  • For many networks samba can provide a complete replacement for windows NT servers, although it does not provide the full range of functionality provided by Active Directory under Windows Server 2000 and Windows server 2003.

  • Samba can also register itself with the master browser on the network so that it would appear in the listing of hosts in windows 95/NT "neighborhood network". In fact, samba itself can act as the master browser ( domain controller ) on the network.

  • Samba can also use LDAP ( Lightweight Directory Access Protocol ) as backend database for storing machine and user account details.

  • Another standard feature of Samba is an ftp like SMB client which allows you to access shared PC resources such as disk or folders and printers.

Packages that are required to have Samba system in the system are shown below.


Package
Description
Samba-*
Basic Samba Server Package
Samba-client-*
This package allows you to setup your linux computer to read shared Microsoft Printers
Samba-common-*
This package includes files required to support Linux as a Samba client and as a samba server.
Samba-swat-*
This GUI tool lets you modify the main samba configuration files.


Configuring a share :

To analyze the way directory are share from the packaged 'smb.cong' configuration. There are 8 examples of shared directories in the standard 'smb.conf' file.

SAMBA Linux to Windows Sharing 

Setup the shares in /etc/samba/smb.conf by editing it as follows
[share1]  -----------------------------------------------------> This is the share name
          comment = share from linux box  ----> A description of the share
          path = /path/to/shared/directory -----> Path to the shared directory
          read only - yes/no ----------------------------> Permissions to the directory
          vaild users = user --------------------------->  User name
          browse able = yes/no ----------------------> Permission to list contents of the  
                                                                       directory
 If you want to share CD/DVD drive
[DVD]
         comment = dvd drive on linux box
         writable = no
         locking =  no
         path = /mount/point/of/dvd
         valid users = user1 ( user name )

Checking the configuration file for errors:
  • After editing the 'smb.conf' file to add the shares that you need, we check it for consistency and syntactic errors.
  • At the shell type:
#testparm
  • this command reads through the configuration file and display errors if any.

Adding Users:
At this stage, we are almost done. To access Samba shares, evey user needs to have a userID and password. Bear in the mind that this userID and passwd is different from the log-in ID that the users uses to log in to the system.
Open your terminal windows and type in the following:
#useradd user1
#passwd user1
changing password for user user1
NEW UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully

#smbpasswd -a user1
NEW SMB password:
Retype new SMB password:
Added user user1

The same username and password that you log onto to the windows PC with. 
When you create a new linux user, it will automatically create a home share for this person. In this case it will be /home/user1.
Now Samba has to be restarted so that all of the changes that we have made will take effect. For starting that samba services use the following command in the command prompt.

#/etc/init.d/smb restart OR
#/etc/init.d/smb start

Accessing the shares via GUI:
                     Accessing shares from a windows machine.
  • Click Start|Run.
  • In the prompt type \\192.168.0.1\share1. 192.168.0.1 is the IP address of the linux machine.
Accessing shares from a linux machine.
  • Open a file browser like nautilus or knoqueror.
  • Type 'smb://192.168.0.1/share1' and press enter to access the share.

Accessing the shares via command line in Linux:
you can access share available from linux machine by mounting the share as your local directory. For mounting use  the following command on the client linux machine.
#smbmount //linuxserver/share name /home/user1 -o username= test password:


                                                     OR
$smbclient  //linuxserver/sharename -u username 
password:
smb:/>

Note:
To access the smb share via a remote machine, we need  to know the username and password on the remote samba server machine.

Global Parameters
[global]
Anything in here applies to samba as a global setting. There is some configuration info here that is important so that samba and your windows pc's will function properly. However some global settings can be overridden by share settings ( more on this later). I will now go through each line and give a brife description of what role it plays in Samba.

workgroup = home
This is the name of your network group. It is important that both samba and windows are in the same workgroup. Please read your windows documentation on how to change your windows pc's workgroup name.

netbios = Samba
Netbios name is what you will see in your windows pc "Network Neighborhood"
for your Samba server. You can name this anything you wish. If you leave it blank, it will default to your host name.

encrypt passwords = yes
Samba can work with encrypted or unencrypted passwords. However windows 98, Windows NT,2000 utilize encrypted passwords. The only time this should be set to no is when you have any older windows systems running on your network ie: Windows 95,3.x if this is the case you will have to do some registry modifications to your windows 98, NT , 2000 to allow them to send unencrypted passwords across the network. Not the most secure situation though.

Share Parameters
[homes]
 When you create a user on your linux pc ( more on this later ) it will automatically create a home folder for you in /home/yourusername. Think of this as your "My Documents" for linux.
read only = no
By default samba will always make any directory read only for security reasons, so we need to let samba know that we want to be able to write to this directory.
browseable = no: defines when you map a network drive to samba, it will map directly to your user directory ie: \\home\mw ( this is my username on linux and samba ) This share /home/mw is browseable only by you. Remember this is much the same as the " My Documents" folder in windows.
path = /data/mp3
This tells us the directory is found on the samba server as /data/mp3, later when we map the network drive on the windows pc, it will be seen as "music" in Network Neighborhood.
browseable = yes
This share will show in network neighborhood as " Music "
Public = yes
Specifies anyone can access and view the contents of /data/mp3
write list = user1
Although anyone can view and excute ( meaning see and play any mp3 in this directory ). For security and practical reason i have set this share so only mw     ( thats me )  and jackie can delete or add files. You can add as many names as you wish to this line ie: , mw, john, tiffany etc. To exclude any person from being  able to access this share altogether, add the line: invalid users = vicky, steve. These names are the logon names from windows and are not case sensitive. They also must have a logon name and samba password on the linux pc.