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.


Thursday, February 23, 2012

Network Information Services

Network Information Services ( NIS )

Descriptions :

The existence of a centralized log on system eases the administrative burdens of network and systems administrators. NIS is one such implementation for linux domains.

Introduction:

  • Network Information Servies ( NIS ) enables you to create user accounts that can be shared across all systems on your network. The user account is crated only on the NIS server. NIS clinets downloads the necessary user name and password data from the NIS server to verify each user login.

  • Network Information Services ( NIS ) originally known as yellow pages, is sometimes called Name Services and follows the client-server architecture. NIS servers maintain replicated servers, with the principal servers being referred to as master servers and the replicated serves referred to as replica or slave servers.

  • NIS master and replica servers provide services to NIS clients. NIS stores information on the master server in a set of files called maps about users, groups, hosts information, address, and network services information. This collection of network information is referred to as the NIS name space.

  • NIS maps store information in a two column table. The first column lists the key and the other column display information about the key. The NIS server responds to the client query based on the information in the maps.

  • An advantage of NIS is that users need to change their passwords on the NIS server only. instead of every system on the network. This makes NIS popular in computer training labs, distributed software development projects or any other situation where group of people have to share many different computers.

  • The disadvantages are that NIS doesn't encrypt the user name and password information send to the client with each login and that all users have access to the encrypted passwords stored on the NIS server.

  • The Lightweight Directory Access Protocol ( LDAP ) offers similar features to NIS but has the advantage of supporting encryption without additional software and can support clients across multiple networks without the need for slave servers. It is for this reason that LDAP has became increasingly popular for this type of application.

Packages required for NIS server and client configuration are given below:

ypserve , yp-tools ------------ server configuration
ypbind ,  yp-tools ------------  client configuration

So before configuration NIS check whether these package are present both in server and client systems by typing the following command in the command prompt.

# rpm -qa yp*

Configuring Network Fine System :

Configuring NFS on server side :

The need for configuring NFS in NIS server is to make the users home directories available across all the remaining linux workstations in the local network. So to export the users home directories across network go to /etc/exports and add the following line

/home    *(rw,sync)

and save changes to the file and come back to the command prompt and type exportfs -a to export users home directories across the network.

Make sure the required nfs, nfslock and portmap daemons are running.

Configuring NFS on client side:

On client side to mount the users respective home directories when they access NIS server for login, create a directory by name home to mount your home directory on the serve to the newly created home directory on the machine from where we are going to access the NFS server. For mounting use the following command.


# mount 192.168.53.2:/home /home/
# mount IP Address:/direcotry /path/

Here 192.168.53.2:/home is home directory of user situated on the NFS server and /home is directory created in the client system.

To unmount the home directory use umount /home.

The other way of mounting the home directory if the user is using auto mounting option. Start configuring auto fs auto mounting. Edit your /etc/auto.master file to refer to file /etc/auto.home for mounting information whenever the /home directory is accessed. After five minutes, autofs umounts the directory.

# vim /etc/auto.master
/home                /etc/auto.home --timeout 600

Edit file /etc/auto.home to do the NIS mount whenever the /home directory is accessed. If the line is too long to view on your screen, you can add a \ character at the end to continue on the next line.


# vim /etc/auto.home


*       -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp \192.168.53.2:/home:&

Start autofs and make sure it starts after the next reboot with the chkconfig command.

#chkconfig autofs on
#service autofs restart

Configuring NIS Server :

Before configuring NIS server make sure that all the NIS related packages are installed and if not install the required packages. After installing the required packages follow the steps given below for configuring NIS.

  • In /etc/sysconfig/network file and add the domain name as test.com


# vim /etc/sysconfig/network
NISDOMAIN= "test.com"

  • Now edit the /etc/yp.conf file since NIS server also have to be NIS clients themselves, so you'll have to edit the NIS client configuration file /etc/yp.conf to list the domain's NIS server as being the server itself or local host.

# /etc/yp.conf -ypbind configuration file
ypserver 127.0.0.1

  • Start the necessary NIS daemons and use the chkconfig command to ensure they start after the next reboot.


# service portmap start
# service yppasswdd start
# service ypserv start
# chkconfig portmap on
# chkconfig yppasswdd on
# chkconfig ypserv on

Brief description of each daemon is shown below :


Daemon Name
Purpose
Portmap
The foundation RPC daemon upon which NIS runs.
Yppasswdd
Lets users change their passwords on the NIS server from NIS clients
Ypserv
Main NIS server daemon
Ypbind
Main NIS client daemon
Ypxfrd
Used to speed up the fransfer of very large NIS maps

To make sure they that all the daemon are running properly, you can use the rpcinfo command from the command prompt.

Initializing NIS Domain:
To create the associated authentication file for the domain we use ypinit command. When you use this command it will prompt for the domain name at some time where we have to specify test.com. Before running this command sure that port map service is running on your system. Use ypinit command as shown below.

# /usr/lib/yp/ypinit -m 
 
At this point, we have to construct a list of the hosts which will run NIS servers. 'user1' is in the list of NIS server hosts. Please continue to add the names for the other hosts, one per line. When you are done with the list, type a "control D".

next host to add: test.com
next host to add:
The current list of NIS servers looks like this:
user1
Is this correct? [y/n] = y
user1 has been set up as a NIS master server.
Now you can run ypinit -s user1 on all slave server.
#
Now start running ypbind and ypxfrd services from the command promp.

Configuring NIS client:
Now on the client side run authconfig command. The authconfig or the authconfig-tui program automatically configures your NIS files after prompting you for the IP address and domain of the NIS server.
#authconfig-tui

Once finished, it should create an /etc/yp.conf file that defines, amongst other things the IP address of the NIS server for a particular domain. It also edit the /etc/sysconfig/network file to define the NIS domain to which the NIS client belongs. In addition, the authconfig program updates the /etc/nsswitch.conf file that lists the order in which certain data sources should be searched for name lookups such as those in DNS, LDAP and NIS.

  • You can also make changes manually by making changes for the following files as shown below.
In /etc/sysconfig/network file and add the domain name as test.com.
#/etc/sysconfig/network
NISDOMAIN="test.com"

  • Now edit the /etc/yp.conf file since NIS servers also have to be NIS clients themselves, so you'll have to edit the NIS client configuration file /etc/yp.conf to list the domain's NIS server as being the server itself or local host.
#/etc/yp.conf - ypbind configuration file
ypserver 192.168.53.2

  • In /etc/nsswitch.conf file, that lists the order in which certain data sources should be searched for name lookups such as those in DNS, LDAP and NIS. Here you can see where NIS entries were added for the important login files.
#/etc/nsswitch.conf
passwd:  files nis
shadow: files nis
group: files nis

  • After completing the editing of files start client service daemons ypbind and port map and verify that they are automatically starting at reboot.

Testing the NIS Server:
For testing access to NIS server you can ru nthe ypcat, ypmatch and getent commands to make sure communication to the server is correct.

#ypcat passwd
#ypmatch user1 passwd
#getent passwd user1


Wednesday, February 22, 2012

Network File System

Network File System ( NFS )

Descriptions :
The presence of Linux workstation in a network will invariably demand the need for allowing remote file access in between system. NFS is a solution that is used to enable UNIX-UNIX file sharing. Implement a NFS server in the network so that other users of the LAN can leverage the functionalities of network file sharing.

Introduction:

NFS ( Network File System ) allows hosts to mount partitions on a remote system and use them as though they are local file systems. This allows the system administrators to store resources in a central location on the network, providing authorized users continuous access to them.

Package required for NFS:

Nfs-utils-*                                   Include basic NFS commands and daemons
Portmap-*                                  Supports secure NFS.RPC connections

Editing the configuration file:

To configure NFS you have to configure /etc/exports file. This is the place where you are going to mount file system that is to be shared in the network. In order to export a particular file system, we have specify it in the following format as shown below in /etc/exports file.

export host1(options)------------------------- hostN(options)

In the above format, in the place of export place the directory which you want to export. In the place of host1 specify the ip address or the network address so that a particular network can access the exported directory. And the options include read and permissions,user permissions etc.

The following methods can be used to specify host names in place of host1:

  • single host --- Where one particular host is specified with fully qualified domain name, hostname, or IP Address.

  • wildcards ---- Where a * or ? character is used to take into account a grouping of fully qualified domain names that match a particular string of letters. Wildcards should not be used with IP Address; however, it is possible for them to work accidentally if reverse DNS lookups fail.

Be careful when using wildcards with fully qualified domain names, as they tend to be more exact than expected. For example the use of *.example.com as a wildcard allows sales.example.com to access and exported file system but not bob.sales.example.com. To match both possibilities both *.example.com and *.*.example.com must be specified.

  • IP networks --- Allows the matching of hosts based on their IP address within a larger network. For example, 192.168.0.0/28 allows the first 16 IP address, from 192.168.0.0 to 192.168.0.15, to access the exported file system but not 192.168.0.16 and higher.


OPTION
DESCRIPTION
ro
Read Only permission
rw
Read and Write permission
sync
All data is written by request
no_root_squash
Allow root user to access exported directory through network
hide
Sharing the directory without including its sub directories for sharing
no_hide
Includes sharing sub directories
no_wdelay
Data is written to share immediately
all_squash
Treat all users as anonymous users
  Example : 
An example for how to enter a directory in /etc/exports file for exporting is given below:
/home            user.test.com(rw,sync)
/user1            *.test.com(rw,no_root_squash,sync)

Here in the first line the home directory can be accessed only by user.test.com. Where as in the second line user1 directory can be accessed by any system in the test.com domain. Here '*' is a wild card which specifies all clients in the domain test.com.

Exporting Files:

After specifying the directory which we want to export in the /etc/exports file, save the configuration and come out of the file and start the nfs service through command prompt using command service portmap start or /etc/init.d/portmap start.
Now for exporting the specified directory,in the command prompt use the following commands.

Command
Description
exportfs -a
Exports all directories for sharing specified in /etc/exports
exportfs -r
Receives list of shared directories after changing the configuration file
exportfs -u
Unexports all directories
exportfs -v
Lists all currently shared directories


Configuration on the client side for accessing directories exports through NFS:
On the client side, in order to view the directories that are exported through NFS use the following command.

#shownmount -e hostname ( IP Address of server )

Which shows all shared files. If you want to mount that directory locally you'll need an empty local directory. So create a directory such as /home/test. Now we can mount the share directory from a particular computer with the following command.
# mount -t nfs enterprise3:/usr/loca /home/test
# mount -t nfs IP address hostname:/server side directory /user side directory
In the above command, enterprise3 is the computer name from where the directory is exported and /usr/local is the exported directory and /home/test is the place where we have mounted the exported directory on to the machine through which you are accessing. '-t nfs' specifies the type of file system.
NOTE:
  •  A file system is a method for storing and organizing computer files and the data they contain to make it easy to find and access them. File systems may use a data storage device such as a hard disk or CD-ROM and involve maintaining the physical location of the files.
  • Portmap service is required to map RPC requests to the correct services. When ever a client contacts the Portmap server with some RPC number the Portmap redirects the client to the intended service.
  • RPC ( remote procedure call ) is a protocol that one program can use to request service from a program located in another computer in a network without having to understand network details. RPC  uses client/server model. The requesting program is a client and service providing program is the server.

Tuesday, February 21, 2012

FTP Server

File Transfer Protocol ( FTP )

Description:

Linux offers powerful networking capabilities. Consequently it has become one of most popular Operating System that make the backbone of the world wide web. One of the popular method of hosting services across the Internet is the use of FTP server that use the File Transfer Protocol to aid file transfers across the Internet. Set-up FTP server for various access needs.

Introduction:

  • If you want to enable other users to download files from a location on your server's hard disk or to upload file to that location then one solution is to set-up an FTP server.
  • When users want to upload/download from your FTP server they use a program called the FTP client.
  • These communications between the FTP server and FTP client takes place using the File Transfer Protocol ( FTP ).
  • FTP is not considered a secure protocol as communications between the FTP client and server are unencrypted. Consequently Secure FTP ( SFTP ) is gaining popularity among users. 
  • Many FTP servers still its disk space and download its files. Anonymous FTP access is used mostly to enable users to access freely available documents program etc. via the internet without access control.
  • 530 Please login with USER and PASS.
FTP Servers included in Linux

Very Secure File Transfer Protocol Daemon ( vsftpd )
TUX
wu-ftpd
gssftpd


Installing the vsftpd FTP server:

Depending on the choices chosen during installation, the FTP daemon may have been installed.

  • Check for it in Applications|System Settings|Add/Remove Application . Check the check box for the vsftp package.
  • To start the FTP service ( enabling users to upload/download files), we can use the services configuration tool located in Application|system Settings|Server Setting|Srvices.
  • Alternatively type service-config-services at the command line.
  • Select vsftpd in the list and then click the start button.
  • Click on file save it.
  • From the command line, use the service command.
# service vsftp start  ( to start the service )
# service vsftp stop   ( to stop the  service )

  • The commands shown above are specific to Linux. A more generic command.
# /etc/init.d/vsftpd start
# /etc/init.d/vsftpd stop


Testing the FTP server :

Now you have setup the FTP server and started the service, we'll adopt the role of the client to quickly test the server. From the command line type the command.

#ftp
   Connected to host.domain/ip-address.
   220 (vsFTPd version)
   530 Please login with USER and PASS.
   530 Please login with USER and PASS.
   KERBEROS_V4 rejected asan authentication type
   Name (ip-address:root):anonymous
   331 Please specify the password.
   Password:
   230 Login successful. 
   Remote system type is UNIX.
   Using binary mode to transfer files.
   ftp> bye
   221 Goodbye.


Configuring an anonymous FTP for file download:

  • Anonymous users can not read form any directory from the machine in which the server is hosted.
  • By default the vsftpd package creates a directory tree starting ar /var/ftp/pub and enables anonymous read access to this directory. Anonymous users connect to the /var/ftp directory when they establish a session with the FTP server.


Setting Up the FTP server:
  1. Place some content in the /vat/ftp/pub directory so that other users can access it.
  2. The owner of l the /var/ftp/pub is the root account and is only permitted to that directory.

Using and FTP client to test anonymous read access:

  1. Now you can test for anonymous access by using an FTP client to try grab a copy of this file via FTP connection.
  2. Both Windows and Linux machines can use FTP using the command line.
  3. FTP clients are given as a default package on the installation of the system.
  4. Connect to the FTP server and log in as the anonymous user.

$ ftp 192.168.53.77 ( ip address )
Connected to 192.168.53.77.
220 ( vsFTPd 2.0.5 )
Name (192.168.53.77:user):anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

  • You can list the files in the current directory. This is the directory where you connected. 

ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r-- 1 0 0  21 feb 13 11.14 file 1
226 Directory send OK.

  • Any Linux command related to file system navigation will be executed in the server. To execute a command in the local system, precede the command with an exclamation mark (!). To change the local directory  , use the 'lcd' commad.
ftp> !pwd
/home/user/Desktop
ftp>lcd~
Local directory now /home/user

  • To download a file, use the 'get' command. To get multiple files, use the 'mget' command.
ftp> get file1
local: file 1 remote: file 1
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for file 1 ( 16 bytes ).
226 File send OK.
16 bytes received in 0.00 secs ( 84.0 kB/s )

  • To exit out of the session, use the bye command.
ftp> bye
221 Goodbye.
$



Configuring and anonymous  FTP server for file upload :

  • Anonymous FTP users can write only into directories that we allow them to write to.
  • By default, vsftpd dose not allow users to upload to the FTP server at all; we must first configure the server to allow anonymous users to write to some directory.

Setting up the FTP server for Anonymous write access:

  • To create a writable directory, you'll need the root account for this. Let's cerate a directory called 'uploads' in the /var/ftp/pub directory.
# mkdir /var/ftp/pub/uploads

  • To set the permission of the upload directory so that it allows write only access to anonymous FTP users.
# chgrp ftp /var/ftp/pub/uploads
# chmod -R 730 /var/ftp/pub/uploads

  • To configure the vsftpd server to allow anonymous upload, edit the configuration file /etc/vdftpd/vsftpd.conf.
#Uncomment this to allow the anonymous FTP user to upload files. This only
#has an effect if the above global write enable is activated. Also, you will 
#obviously need to create a directory a directory writable by the FTP user.
#anon_upload_enable = YES

Remove the hash in front of the previous line. It should now look like.

 anon_upload_enable=YES

  • Restart the FTP service for the changes to take effect.

Using an FTP client to test anonymous write access:

  • Connect to the server and authenticate as anonymous user.
$ftp 10.0.2.15
Connected to 10.0.2.15.
220 ( vsFTPd 2.0.1 )
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type.
Name (10.0.2.15:root):  anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

  • Change to the directory in which you have write permissions.

ftp> cd pub/uploads
250 Directory successfully changed.
ftp>

  • Upload the file you want using the 'put' command. For multiple files use the 'mput' command.


ftp> put ftp
local:ftp remote:ftp
227 Entering Passive Mode (10,0,2,15,110,4)
150 Ok to send data.
226 File receive OK.
575 bytes send in 0.00027 seconds (2.1e+03 Kbytes/s)
ftp>


FTP authentication vis a system account :

Your system has an user account called 'user'. This account can be used to gain access to the FTP server. These users will be presented their HOME directories to work with.

$ ftp 10.0.2.15
Connected to 10.0.2.15.
220 (vsftpd 2.0.1)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBERROS_V4 rejected as an authentication type
Name (10.0.2.15:root):user
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

Disabling Local System Users Account for FTP:

  • By default the users logged in through FTP would have the same permission to read, write and execute the contents of their home directory via FTP that they would have had if they were accessing the directory by logging in at the computer.
  • Authentication via FTP is not encrypted so allowing FTP via user accounts is actually not a good idea to allow access to your system if you have got anything sensitive to protect.
  • Edit the vsftpd configuration file to disallow access to the system users and comment the following line.
# Uncomment this to allow local users to log in.
local_enable=Yes

This line should then read as

# uncomment this to allow local users to log in.
# local_enable=YES

Blocking FTP Access for selected user account:

  • To deny FTP access to individual users edit the vdftpd configuration file to allow system users access to the FTP server.
  • Edit the /etc/vsftpd.ftpusers file. This file contains the list of system users no allowed to access to the FTP server.
  • Add the name of the users that you want to deny access to. In the lab,we add the  user 'user'.
  • Save and Exit and restart the FTP server daemon.
  • Try logging in as the user.
$ftp 10.0.2.15
connected to 10.0.2.15.
220 (vdftpd 2.0.2)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (10.0.2.15:root):user
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp>

Configuring an FTP greeting banner:

  • Open the vdftpd configuration file for editing.
  • Search for the line that asks you to customize a login banner.
# you may fully customize the login banner string:
# ftpd_banner=welcome to -------- services.
  • Uncomment the line that says 'ftpd_banner' and write and appropriate login banner.
  • Restart the FTP server and see if your banner has taken effect.

$ftp 10.0.2.15
connected to 10.0.2.15.
220 Welcome to the ------------ service.
Name (10.0.2.15:root):