Monday, March 26, 2012

Shell Script to crate user from old server to new server

Shell Script to crate user from old server to new server.

1) copy /etc/passwd file from old server to new server password.txt in same location where you execute same script

shell script

#!/bin/bash
# Script to add a user to Linux system
# -------------------------------------------------------------------------

groupadd -g 501 amco
#echo "Default Group Amco created"
usernamelist="`cat password.txt | cut -d ":" -f1 `"
#fullname="`cat password.txt |cut -d":" -f5`"
for i in $usernamelist
do
if [ $(id -u) -eq 0 ]; then
        
#    read -p "Enter username : " username
    #read -s -p "Enter password : " password
    username="$i"
    password="123456"
    fullname="`grep -i $username password.txt | cut -d":" -f5`"
    useruid="`grep -i $username password.txt | cut -d":" -f3`"
    egrep -w "^$username" /etc/passwd >/dev/null
    if [ $? -eq 0 ]; then
        echo "$username exists!"
#        exit 1
    else
        pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
        useradd -m -u "$useruid" -G amco -c "$fullname" -p "$pass" -d /home/$username "$username"
        [ $? -eq 0 ] && echo "User $username has been added to system!" || echo "Failed to add a user $username!"
        #`chage -d 0 $username`   
    fi
else
    echo "Only root may add a user to the system"
    exit 2
fi
done




BLOCK USB to connect linux server

BLOCK USB to connect linux server

echo 'blacklist usb_storage' >/etc/modprobe.d/blacklist-usb_storage
echo 'modprobe -r usb-storage' >> /etc/rc.local

Tuesday, March 20, 2012

ISCSI TARGET ON RHEL 6


ISCSI TARGET SERVER HOW TO ON REDHAT6-----------------------------------------------------------
(THIS Practical is created in vmware machine )

lab setup :-

server : ip add 192.168.0.10
hostname = server.example.com

client= ip add 192.168.0.100
hostname= client1.exmaple.com

-------------------------------------------********************************-------------------------------------------------------
# install following package
# yum -y install scsi*
then
# chkconfig tgtd on

step 2 add vitual hardisk and create lvm on that hardisk
and mount it the


step 3
# vim /etc/tgt/targets.conf
And add this line at end of the file
<target iqn.2011-2012.com.exmaple:server.target1>

backing-store /dev/wgroup/whare

</target>


then test discover the iSCSI target from the target server itself, using the following command:
#iscsiadm -m discovery -t sendtargets -p 192.168.0.10
  192.168.0.10:3260,1 iqn.2011-2012.com.exmaple:server.target1

then u succseefully created ISCSI TARGET SERVER
 ------------------------------------------------------------------------------------------------------------
Client side := 1st step Run follwing command

 # iscsiadm -m discovery -t st -p 192.168.0.10(serverip)


 192.168.0.10:3260,1 iqn.2011-2012.com.exmaple:server.target1


 then copy only for (iqn.2011-2012.com.exmaple:server.target1)


 and past it like this


 # iscsiadm -m node -T iqn.2011-2012.com.exmaple:server.target1 –login

 it will give mesg successful


# then run the fdisk -l itwill show u server side disk thats it



Monday, March 19, 2012

UMOUNT FORCEFULLY COMMAND


  • umount file system when device is busy


          # umount /data
              Umount /dev/sdb1 : device is busy
               Umount /dev/sdb1 : device is busy
         So
                   # fuser –m /data
                      /data     : 4582c

               Then give command
                  # ps –ef |grep 4582

              And kill the process

                Then unmount the file system
 Or 

give command for umount 

# umount -l /data 

SWAP COMMAND


  • Clear the swap space in linux


First we want to see what is currently being use

    # free

Then checkout swap use or not


Then give command

# swapoff –a and

# free


Then
# swapon  -a

# free


Rsync command and tar.gz commands


  • If u want to transfer data 1 server to another server give following command

               # rsync –auv source file path or file name                            remotepath(192.168.252.212:/home/amol/Desktop)




·        List the contents of a tar.gz file


             #  tar –tvf  file.tar.gz

·        List the contents of a tar.bz2 file

# tar -jtvf file.tar.bz2


  • How to extract tar.gz file in another directory

         # tar –zxvf  file.tar.gz  -C destination path(/amol)


  • How to create tar.gz file
   #  tar –zcvf  file.tar.gz  your file name like file1

finding package of particuler file belonging


  • How to check that a particular filebelong to which package.
           Ans.

       Before this run command

      # which  rescan-scsi-bus.sh
       /usr/bin/ rescan-scsi-bus.sh

      Then go to that path and run below command


       # rpm –qf  /usr/bin/rescan-scsi-bus.sh
        sg3_utils-1.27-17.7

GRUB PASSWORD IN SUSELINUX11


                                                         SETTING GRUB PASSWORD IN SUSE LINUX 11

1st step

# grub-md5-crypt
Passwor: 
Reenterpassword:
Sdfdsfdsfsdafdasfsdf$$$$

# then copy the encrypted password in menu.lst

Like this
# vim /boot/grub/menu.lst

Add line below
Default 0
Timeoute 0

Password –md5  Sdfdsfdsfsdafdasfsdf$$$$


Then restart the server 

DENY ROOT SSH LOGIN


ALLOW   NORMAL USER  LOGIN VIA PUTTY


In SLES 11

Server :-  192.168.0.101

Edit the line

# vim /etc/ssh/sshd_config
unComment the PermitRootLogin     Yes
and change like this
 
PermitRootLogin   no

And save the file

Then restart the ssh service

Create normal user ( amol)



Client machine :- 192.168.0.50

SSH BANNER


                 Setting up banner when Putty through Login

In SLES 11 =:

Edit like this

#   cat /etc/issue

                                      BSE  Ltd.



       "This system is for the use of authorized personnel only. Unauthorized or improper use of this system may
result in administrative disciplinary action and/or legal action by the BSE Ltd. management. By continuing to use
this system indicate your awareness of IS policies of BSE Ltd. and adhering to the same."




#  vim /etc/ssh/sshd_config

Add following line
Or
Edit the Banner none line 

# no default banner path
Banner /etc/issue

Then restart the ssh service

Pure-ftpd configuration on SUSE Linux


                                  Pure-ftpd configuration on SUSE Linux


Lab scenario :

ftp-server :192.168.0.102
client :192.168.0.101

on ftpserver we create 3 users

·          ftpadmin = were all data keeping in like as
/home/ftpadmin/data/i586/

And change the ownership like this

#Chown –R  ftpadmin.users /home/ftpadmin/data

Next  user is bsembr6385

And change the ownership like this

# chown –R ftpadmin:users  /home/bsembr6385

We change the ownership becoz client side bsembr6385 login and acess the data in /home/ftpadmin/data


Or

If u want restrict the /home/ftpadmin/data to bsembr6385

Then run the follwing command

# chmod 744 –R  /home/ftpadmin/data

Then bsembr6385 cannot see te content of the Data directory



1step

Install pure-ftpd package from dvd od sles11

2nd step

Start the service

# /etc/init .d /pure-ftpd restart

 The go to client side




REAR OSBACKUP IMAGE


                                                          RELAX AND RECOVER (OS BACKUP)
------------------------------------------------------------------------------------------------------------------------------------------------


Rear server – 192.168.0.102
# install rear package
# showmount –e 192.168.0.101
Export lisr for 192.168.0.101
/rear_backup *
# vi m /e tc/rear/local.conf
BACKUP = N ETFS
NETFS_URL=nfs://192.168.0.101/rear_backup
OUTPUT=ISO
MODULES_LOAD=(vmxnet)
# rear mkbackup
Relax & Recover Version 1.7.23/2009-12-09
Warning ! the NETFS backup method should not be your primary
Backup solution , because it does not fulfill the requirement
The preparatipon  phase ok
Physical devices that will be recover :/dev/sda
Creating root fs layout ok
Copy files and directory ok
Copy kernel moduls ok
Create initiramfs ok
Creating archive nfs://192.168.0.102/rear_backup /santy/backup.tar.gz
Archive size is 25 mb

NFS server 192.168.0.102
# cd /rear_backup/rear
Backup.tar.gz
Backup.txt
README
Rear.iso
VERSION
# copy REAR.iso on vmhost and boot from Rear .iso

YUM SERVER IN RHEL 5


On server side

Ip add = 192.168.0.25
Hostname = server1
# mount /dev/cdrom /me        dia
# cp –r /media/RHEL/Server /var/ftp/pub/
# rm –r /var/ftp/pub/Server/repodata
# createrepo –g /media/RHEL/Server/repodata/comps-rhel5-server-core.xml /var/ftp/pub/Server/
# cp /etc/yum.repos.d/rhel.debuginfo.repo /ftp.repo
#edit file like that for local yum
[server]
name=server
baseurl=file:///var/ftp/pub/Server
enabled=1
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release


Then run 

# yum list

-----------------------------------------------------------
And for client on vsftpd service and then
Edit the file of client before editing move all file in yum.repose.d  and move only one file and edit this file like

# mv /etc/yum.repos.d/* /
#cp /centos-base.repo /etc/yum.repos.d/
#mv /etc/yum.repos.d/centos-base.repo /etc/yum.repos.d/ftpserver.repo
# vim /etc/yum.repos.d/ftpserver.repo
[ftpserver]
name=base
baseurl=ftp://192.168.0.25/var/ftp/pub/Server/
enable=1
gpgcheck=0