Tuesday 27 March 2012

Basic Linux Commands

You can click below on some Basic Commands    :  Basic Commands   & Basic Commands 2

Monday 26 March 2012

Features in RHEL6

1. ext4 file system is introduced.
2. xen is removed and kernel virtualization machine (KVM) is introduced.
3. neat command is removed.
4. portmap service is removed.
5. iscsi is introduced, which supports for SAN.
6. rpmbuild is available, which is used to create our own rpms.
7. File encyption is added.
8. palimpsest is available for disk management.
9. Virtual machine will run only on 64bit processors.
10. postfix service is recommended instead of sendmail service

Friday 23 March 2012

Linux Disk Quota Implementation

Linux User Disk Quota Implementation
What is disk quota?
Ans : Disk quota is  restricting the disk-space usage to the users. We have to remember one  thing when we are dealing with disk quota i.e. Disk Quota can be applied only on disks/partitions not on files and folders.

how we can implement disk quota?
Disk quota can be implemented in two ways

a. On INODE
b. On BLOCK

What is an INODE?
Ans : In Linux every object is consider as file, every file will be having an inode number associated and this is very much easy for computer to recognize where the file is located.

Inode stands for Index Node, and is the focus of all file activities in the UNIX file-system.
Each file has one inode that defines the file’s type (regular, directory, device etc), the location on disk, The size of the file, Access permissions, Access times.
Note that the file’s name is not stored in the inode.

So how to know what is your file Inode number?
Ans : Its just simple execute ls -i on your file.
ls -i test.txt
13662 test.txt
 
I think now you got what is INODE? Lets move on to BLOCK.
BLOCK A block usually represents one least size on a disk, usually one block equal to 1kb. Some terms in Disk quota.

Soft limit: This is the disk limit where the user gets just a warning message saying that your disk quota is going to expire. This is just a warning, no restriction on data creation will occur at this point.

Hard limit : This is the disk limit where user gets error message, I repeat user gets error message stating that unable to create data.

Implementing QUOTA :
Step1 : Select/prepare the partition for quota, most of the time disk quota is implemented for restricting users not to create unwanted data on servers, so we will implement disk quota on /home mount point.

#vi /etc/fstab
Edit the /home mount point as follows
Before editing
/dev/hda2 /home ext3 defaults 0 0

after editing
/dev/hda2 /home ext3 defaults,usrquota 0 0
 
Step2 : Remounting the partition(this is done because the mount table should be updated to kernel). Other wise you can reboot the system too for updating of mount table, which is not preferred for live servers.

#mount -o remount,rw /home
Here -o specifies options, with remounting /home partition with read and write options.
 
Step3 : Creating quota database
 
#quotacheck -cu /home
The option -c for creating disk quota DB and u for user
Check for user database is created or not when you give ls /home you have to see auota.user file in /home directory,which contains user database.
Step4 : Switching on quota
#quotaon /home
Now get the report for default quota values for user sadeek
#repquoata -a | grep sadeek
sadeek_mohd --    4       0               1     0     0
sadeek_m --       4       0       0       1     0     0
sadeek_test --   16       0       0       4     0     0

Step5 : Now implementing disk quota for user sadeek_moh on /home mount point(/dev/hda2)
#setquota -u sadeek_mohd 100 110 0 0 /dev/hda2
 
Step6 : Checking quota is implemented or not login to user sadeek_mohd and execute this command
#repquota -a
or
#quota
Step7 : Keep creating data, once 100MB is reached user will get an warning message saying, and when he reaches 110MB he cannot create any more data.
Hint : To create a data file you can use seq command as below
#seq 1 10000 > test.txt
this command will create a file with 10000 lines with numbers in it.
Removing quota :
To do this one, all the users should log out from the system so better do it in run level one.
Step8 : Stop the disk quota
 
#quotaoff /home

Step9 : Removing quota database which is located /home
#rm /home/aquota.user

Step10 : Edit fstab file and remove usrdata from /home line
#vi /etc/fstab

Before editing
/dev/hda2 /home ext3 defaults,usrquota 0 0

After editing
/dev/hda2 /home ext3 defaults 0 0
Step11 : Remount the /home partition

#mount -o remount,rw /home
That’s it you are done with Disk Quota Implementation in Linux. Now test yourself in creating Linux user disk quota on your own.
 

Wednesday 21 March 2012

Configure linux samba server step by step


Configure Linux samba server step by step guide example and implementation

Exam question There are mixed lots of System running on Linux and Windows OS. Some users are working on Windows Operating System. There is a /data directory on Linux server should make available on windows to only sadeek should have right to connect with samba server . Configure to make available.
Configure samba server

How to make a Samba Server on RHEL6
Install Samba packages in your machine by yum command:
[root@sadeek~]$ yum install samba* -y

Open Samba's configuration file:

[root@sadeek ~]$ vi /etc/samba/smb.conf
# at line 58 add the following
unix charset = UTF-8
dos charset = CP932

# at line 75 change to the windows workgroup.
workgroup =  WORKGROUP
# at line 81 uncomment and change the ip addresses.
hosts allow = 127. 192.168. 
(127 is for local host and your machine virtual ip if you are using a VM).
# at line 102 change the parameters.
security = user

[root@sadeek ~]$ vi /etc/sysconfig/iptables
Add the line at the last before commit.
-A INPUT -i vmnet6 -j ACCEPT  (If using VMPlayer).
-A INPUT -i virbr0 -j ACCEPT (If using Virt-Manager).
(The values of vmnet6 and virbr0 may change as per your machine's config.).

Restart service iptables:
[root@sadeek ~]$ service iptables restart
Enable sharing of home directories:
[root@sadeek~]$ setsebool -P samba_enable_home_dirs=on

Now set a password for the user who is going to access that in windows machine:
[root@sadeek~]$ smbpasswd -a sadeek
New SMB password:
Retype new SMB password:
Now restart samba services:
[root@sadeek ~]$ service smb restart
[root@sadeek~]$ service nmb restart

Now make these services to be enabled at boot time so that you need not to start those again and again.
[root@sadeek~]$ chkconfig on smb
[root@sadeek~]$ chkconfig on nmb
Task to be performed on Windows Box:
Double-click the "My Computer" icon on the desktop.
In the address bar, type "\\192.168.122.123" [Your server ip]without the quotes and hit Enter
Username: sadeek (Username to be used when you did smbpasswd -a USERNAME).
Password: Which you used while setting smbpasswd.
Check "Remember my password" so you need not to enter password again and again.
Click on ok.
Right-click the folder named sadeek [USERNAME].
Choose "Map Network Drive".
Ensure that "Reconnect at Logon" is checked

Tuesday 20 March 2012

ssh-keygen: password-less SSH login

SSH is often used to login from one machine to another machine, There are number of methods to achieve this but mostly in every method it requires authentication..... It also does require authentication but for one time only i.e. for the first time you need to do a setup and for rest of the times when you will try to login via ssh it will not ask for any password.

you just need to generate your own personal set of private/public key pair. ssh-keygen is used to generate that key pair.

How to generate public/private key

root@server:/other_part# ssh-keygen -t rsa Press  (enter)
generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):   (save your default  on default location)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.  (enter)
Your public key has been saved in /root/.ssh/id_rsa.pub.   (enter)
The key fingerprint is:
dc:20:59:db:43:6a:8c:52:7a:08:08:10:0b:eb:da:3d root@server
The key's randomart image is:
+--[ RSA 2048]----+
|Bo.   . . .      |
|oo . + = =       |
|o   + = * o      |
|.    o + o .     |
| .      S .      |
|.. .             |
|. . E            |
|     .           |
|                 |
+-----------------+
|++E...           |
|o.oo.            |
+-----------------+
Now copy private key on remote machine with below mention command

root@server:/other_part# ssh-copy-id -i /root/.ssh/id_rsa 172.27.24.75
root@172.27.24.75's password:  (Enter Password)
Now try logging into the machine, with "ssh '172.27.24.75'", and check in:
  ~/.ssh/authorized keys

to make sure we haven't added extra keys that you weren't expecting.

While you are copying the private key then it will ask password.. Now try login again on remote machine it will not ask the password

root@server:/other_part# ssh 172.27.24.75
Last login: Wed Feb  5 12:36:46 2014 from server.oasis.com
[root@virtual ~]# 
njoy :)

Monday 19 March 2012

6 Stages of Linux Boot Process


Press the power button on your system, and after few moments you see the Linux login prompt.
Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?
The following are the 6 high level stages of a typical Linux boot process.


1. BIOS
BIOS stands for Basic Input/Output System
Performs some system integrity checks
Searches, loads, and executes the boot loader program.
It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F2 of ESC, but it depends on your system) during the BIOS startup to change the boot sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR
MBR stands for Master Boot Record.
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
It contains information about GRUB (or LILO in old systems).
So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB
GRUB stands for Grand Unified Bootloader.
If you have multiple kernel images installed on your system, you can choose which one to be executed.
GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
          root (hd0,0)
          kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
          initrd /boot/initrd-2.6.18-194.el5PAE.img
As you notice from the above info, it contains kernel and initrd image.
So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel
Mounts the root file system as specified in the “root=” in grub.conf
Kernel executes the /sbin/init program
Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
initrd stands for Initial RAM Disk.
initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init
Looks at the /etc/inittab file to decide the Linux run level.
Following are the available run levels
0 – halt
1 – Single user mode
2 – Multiuser, without NFS
3 – Full multiuser mode
4 – unused
5 – X11
6 – reboot
Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
Typically you would set the default run level to either 3 or 5.

6. Runlevel programs
When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
Depending on your default init level setting, the system will execute the programs from one of the following directories.
Run level 0 – /etc/rc.d/rc0.d/
Run level 1 – /etc/rc.d/rc1.d/
Run level 2 – /etc/rc.d/rc2.d/
Run level 3 – /etc/rc.d/rc3.d/
Run level 4 – /etc/rc.d/rc4.d/
Run level 5 – /etc/rc.d/rc5.d/
Run level 6 – /etc/rc.d/rc6.d/
Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
Under the /etc/rc.d/rc*.d/ direcotiries, you would see programs that start with S and K.
Programs starts with S are used during startup. S for startup.
Programs starts with K are used during shutdown. K for kill.
There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
That is what happens during the Linux boot process.

Linux Filesystem Management

badblocks
Used to search a disk or partition for badblocks.
cfdisk
Similar to fdisk but with a nicer interface.
debugfs
Allows direct access to filesystems data structure.
df
Shows the disk free space on one or more filesystems.
dosfsck
Check and repair MS-Dos filesystems.
du
Shows how much disk space a directory and all its files contain.
dump
Used to back up an ext2 filesystem. Complement is restore.
dumpe2fs
Dump filesystem superblock and blocks group information. Ex: dumpe2fs /dev/hda2
e2fsck
Check a Linux second extended filesystem.
e2label
Change the label on an ext2 filesystem.
exportfs
Used to set up filesystems to export for nfs (network file sharing).
fdisk
Used to fix or create partitions on a hard drive.
fdformat
Formats a floppy disk.
fsck
Used to add new blocks to a filesystem. Must not be run on a mounted file system.
hdparm
Get/set hard disk geometry parameters, cylinders, heads, sectors.
mkfs
Initializes a Linux filesystem. This is a front end that runs a separate program depending on the filesystem's type.
mke2fs
Create a Linux second extended filesystem.
mkswap
Sets up a Linux swap area on a device or file.
mount
Used to mount a filesystem. Complement is umount.
rdev
Query/set image root device, swap device, RAM disk size of video mode. What this does is code the device containing the root filesystem into the kernel image specified.
rdump
Same as dump.
rmt
Remote magtape protocol module.
restore
Used to restore an ext2 filesystem.
setfdprm
Set floppy drive parameters.
swapoff(8)
Used to de-activate a swap partition.
swapon(8)
Used to activate a swap partition.
sync
Forces all unwritten blocks in the buffer cache to be written to disk.
tune2fs
Adjust tunable filesystem parameters on second extended filesystems.
umount
Unmounts a filesystem. Complement is mount.

Linux Configuration Files

profile
System wide environment and startup script program.
/dev/MAKEDEV
The /dev/MAKEDEV file is a script written by the system administrator that creates local only device files or links such as device files for a non-standard device driver.
/etc/aliases
Where the user's name is matched to a nickname for e-mail.
/etc/bootptab
The configuration for the BOOTP server daemon.
/etc/crontab
Lists commands and times to run them for the cron deamon.
/etc/dhcpd.conf
The configuration file for the DHCP server daemon.
/etc/ethers
File for RARP mapping from hardware addresses to IP addresses. See the man page ethers(5).
/etc/exports
The file describing exported filesystems for NFS services.
/etc/fdprm
The floppy disk parameter table. Describes the formats of different floppy disks. Used by setfdprm.
/etc/filesystems
Can be used to set the filesystem probe order when filesystems are mounted with the auto option. The nodev parameter is specified for filesystems that are not really locally mounted systems such as proc, devpts, and nfs systems.
/etc/fstab
Lists the filesystems mounted automatically at startup by the mount -a command (in /etc/rc or equivalent startup file).
/etc/group
Similar to /etc/passwd but for groups rather than users.
/etc/groups
May contain passwords that let a user join a group.
/etc/gshadow
Used to hold the group password and group administrator password information for shadow passwords.
/etc/host.conf
Specifies how host names are resolved.
/etc/hosts
List hosts for name lookup use that are locally required.
/etc/HOSTNAME
Shows the host name of this host. Used for support of older programs since the hostname is stored in the /etc/sysconfig/network file.
/etc/inittab
Configuration file for init, controls startup run levels, determines scripts to start with.
/etc/inetd.conf
Sets up the services that run under the inetd daemon.
/etc/issue
Output by getty before the login prompt. Description or welcoming message.
/etc/issue.net
Output for network logins with LINUX version
/etc/ld.so.conf
Configuration file for ld.so, the run time linker.
/etc/lilo.conf
Configuration file for LILO.
/etc/limits
Limits users resources when a system has shadow passwords installed.
/etc/localtime
In Debian the system time zone is determined by this link.
/etc/login.defs
Sets user login features on systems with shadow passwords.
/etc/logrotate.conf
Configures the logrotate program used for managing logfiles.
/etc/magic
The configuration file for file types. Contains the descriptions of various file formats for the file command.
/etc/motd
The message of the day, automatically output by a successful login.
/etc/mtab
A list of currently mounted file systems. Setup by boot scripts and updated by the mount command.
/etc/named.conf
Used for domain name servers.
/etc/networks
Lists names and addresses of your own and other networks, used by the route command.
/etc/nologin
If this file exists, non-root logins are disabled. Typically it is created when the system is shutting down.
/etc/nsswitch.conf
Name service switch configuration file.
/etc/passwd
The user database with fields giving the username, real name, home directory, encrypted password and other information about each user.
/etc/printcap
A configuration file for printers.
/etc/profile, /etc/cshlogin,
/etc/csh/cshrc

Files executed at login or startup time by the Bourne or C shells. These allow the system administrator to set global defaults for all users.
/etc/protocols
Describes DARPA internet protocols available from the TCP/IP subsystem. Maps protocol ID numbers to protocol names.
/etc/rc or /etc/rc.d or /etc/rc?.d
Scripts or directories of scripts to run at startup or when changing run level.
/etc/rc.d/rc0.d
Contains files used to control run level 0. Usually these files are softlink files.
/etc/rc.d/rc1.d
Contains files to control run level 1. Scripts beginning with an S are for start, K for kill.
/etc/rc.d/rc.sysinit
Init runs this when it starts.
/etc/resolv.conf
Configures the name resolver, specifying the address of your name server and your domain name.
/etc/securetty
Identifies secure terminals from which root is allowed to log in.
/etc/services
Lists the network services that the system supports.
/etc/shadow
Shadow password file on systems with shadow password software installed. Shadow passwords move the encrypted password files from /etc/passwd to /etc/shadow which can only be read by root.
/etc/shadow.group
Systems with shadow passwords may have this file.
/etc/shells
Lists trusted shells. The chsh command allows users to change their login shell to shells listed only in this file.
/etc/skel/.profile
Can be used by administrator to set the editor environment variable to some editor that is friendly to new users.
/etc/sudoers
A list of users with special privileges along with the commands they can execute.
/etc/smb.conf
The configuration file for setting up Samba services.
/etc/sysconfig/amd
Used to configure the auto mount daemon.
/etc/sysconfig/clock
Used to configure the system clock to Universal or local time and set some other clock parameters.
/etc/sysconfig/i18n
Controls the system font settings.
/etc/sysconfig/init
This file is used to set some terminal characteristics and environment variables.
/etc/sysconfig/keyboard
Used to configure the keyboard.
/etc/sysconfig/mouse
This file is used to configure the mouse.
/etc/sysconfig/network-scripts/ifcfg-interface
Defines a network interface.
/etc/sysconfig/pcmcia
Used to configure pcmcia network cards.
/etc/sysconfig//routed
Sets up dynamic routing policies.
/etc/sysconfig/static-routes
Configures static routes on a network.
/etc/sysconfig/tape
Used for backup tape device configuration.
/etc/X11/XF86Config
The configuration file for the X server.
/etc/syslog.conf
Configuration file for the syslogd daemon.
/etc/termcap
The terminal capability database. Describes by what "escape sequences" various terminals can be controlled. See terminfo, termcap, curs_termcap man pages.
/etc/terminfo
Details for terminal I/O.
/etc/usertty
This file is used to impose special access restrictions on users.
$HOME/.bashrc
User aliases, path modifier, and functions.
$HOME/.bash_profile
Users environment stuff and startup programs.
$HOME/.bash_logout
User actions to be done at logout.
$HOME/.hushlogin
When this file exists in the user's home directory, it will prevent check for mail, printing of the last login time, and the message of the day when the user logs in.
$HOME/.inputrc
Contains keybindings and other bits.
$HOME/Xrootenv.0
Has networking and environment info.
/proc/cpuinfo
Information about the processor such as its type, make and performance.
/proc/devices
A list of devices configured into the currently running kernel.
/proc/dma
Shows which DMA channels are being used at the moment.
/proc/filesystems
Filesystems that are configured into the kernel. The file used to detect filesystems if the /etc/filesystems does not exist.
/proc/ioports
Shows which I/O ports are in use at the moment.
/proc/interrupts
Shows which interrupts are in use and how many of each there have been.
/proc/kcore
An image of the physical memory of the system.
/proc/kmsg
Messages output by the kernel. These are also routed to syslog.
/proc/ksyms
Symbol table for the kernel.
/proc/loadavg
The load average of the system.
/proc/meminfo
Information about memory usage, both physical and swap.
/proc/modules
Which kernel modules are currently loaded.
/proc/mounts
Contains information on filesystems currently mounted, similar to /etc/mtab
/proc/net
Contains status information about network protocols.
/proc/self
A symbolic link to the process directory of the program that is looking at /proc. When 2 process look at proc, they get different links.
/proc/stat
Various statistics about the system such as the number of page faults since the system was booted.
/proc/uptime
The time the system has been up.
/proc/version
The kernel version.
/tmp/fvwmrca01339
FVWM-M4 defines. Contains networking, Xwindows, other setup info.
/usr/lib/zoneinfo
Time zone datafiles are stored here on the Debian system
/var/log/lastlog
Used by finger to tell when a user was last logged in.
/var/log/wtmp
Binary info on users that have been logged on. The last command uses this info.
/var/run/utmp
Contains information about users currently logged in. Who and w commands use this file.
/var/named/root.hints
Used for domain name server. Placed here optionally, but this is the normal location.
/var/named/*
Files used by domain name server. Placed here optionally, but this is the normal location.
/var/log/btmp
Used to store information about failed logins. This file must be first created to activate it.
/var/log/lastlog
Contains information about the last time a login was done on the system. Works with lastb(1).
/var/log/maillog
The normal system mail log file.
/var/log/messages
The main system message log file.
var/log/secure
System tracking of user logins. Check this file periodically.
/var/spool/mail
Where mailboxes are usually stored.

What are the main differences between RHEL4 & RHEL5 and RHEL 6

#########RHEL4 and RHEL 5 ########################
XEN, YUM and improved SELinux
all the features updated with better options
Better GUI support then RHEL4
YUM over RPM package management
IPTables and SELinux for more secure environment
ext2 & ext3 file system
In RHEL 4 SELinux Block only 13 services, But on RHEL 5
SElinux Block 80 services
 ###############################################

Difference between RHEL 4 and RHEL 5 :
1) In RHEL 4 SELinux Block only 13 services, But on RHEL 5 SElinux Block 80 services.

2) RHEL 4 have ext2 filesystem, but RHEL 5 we have ext3 filesystem that support Journal.

3) RHEL 4 have no virtualization Feature, but in RHEL 5 we have virtualization with Hypervisor-V.

4) In RHEL 4 we have no Yum, But in RHEL 5 we have Yum available.

#####################################################


NMAP Network Mapper