Shashikant shah

Thursday 26 February 2015

Installing and Configuring RSH on Linux

rsh  is used to execute commands on a remote machine.
The rsh command  executes the   command or a program in another host from current working  machine without having to login into that remote machine  by entering a password as in ssh. You can run any unix command, or a shell script of a remote host.

Requirement :-
Remote Machine access without password.

Server :- 192.168.0.10 Server.example.com

Client:-192.168.0.11 client.example.com

192.168.0.10 server.example.com
User :- test

192.168.0.11 client.example.com
User :- test1

1.Both Machine in  /etc/hosts file :-

192.168.0.10  server.example.com server
192.168.0.11 client.example.com client


2.Install some package at Server.example.com :-

# yum install xinetd
# yum install rsh-server rsh*
# rpm -qa|grep -i ^rsh-server

Server side :-

3.Now you need to Edit /root/.rhosts to add lists of hosts that can access without password. If you want to allow access to everyone without password, you need to put '+' in the file. A '+' indicates allowing everyone.

# vi /root/.rhosts
client.example.com root
cilent.example.com test1
# chmod 600 /root/.rhosts

4.test1 user access all data from server machine as a user test.:-
#vim /home/test/.rhosts
client.example.com test1

Note :-Test1 user access remote machine “server.example.com” and login as a test user.  

5.Add a full permission to use the command over the network. Plus sign will give a full permission.
vi /etc/hosts.equiv + +

6.Now you need to allow RSH , RLogin and Rexec to be used.  Open these files one by one and then set the "disable=no"

/etc/xinetd.d/rsh ,
/etc/xinetd.d/rlogin 
 /etc/xinetd.d/rexec

7. Now you need to modify the file  to allow password less  to the machine.

a)/etc/pam.d/rlogin
b)/etc/pam.d/rsh
c)/etc/pam.d/rexec

BEFORE: auth    required        pam_rhosts_auth.so

AFTER : auth    required        pam_rhosts_auth.so promiscuous

8.Enable to services :-

# chkconfig rsh on
# chkconfig rexec on
# chkconfig rlogin on
# chkconfig xinetd on

9.Restart xinetd service:-

# service xinetd restart

10.Add line in /etc/securetty :-
rsh,
rlogin
rexec

Client side :-

11.Testing  on client.example.com, rlogin and rsh to nodes without passwords:-

# yum install rsh

As a login “root” user and  run below commands :-

# rlogin 192.168.0.10
# rsh 192.168.0.10
# rsh 192.168.0.10 -l root ls -al /tmp

As a login “test1” user and run below command :-
# rsh 192.168.0.10 -l test

# rsh 192.168.0.10 -l test ls -al /tmp

# rsh 192.168.0.10 -l root

12.Copy data command  :-

# rcp –r  data test@server.example.com:
# rcp –r  file test@server.example.com:data

13.check port for rsh :-

# netstat -n --inet


Tuesday 24 February 2015

check ssh connection to remote host

#!/bin/bash

count=$(netstat -ntpa | grep ssh | grep -i EST* | wc -l)

if [ "$count" -gt 0 ]; then
comm=$(netstat -ntpa | grep ssh | grep -i EST* | awk '{print $7}' |
cut -d "/" -f1 > /tmp/ssh_1)

        for ID in `cat /tmp/ssh_1`
do
        user=`who -a | grep -ih "\W*\w*$ID\w*\W*" | grep -w  $ID | awk
'{print $1}'`
        IP=`who -a | grep -i $ID | awk '{print $8}' | cut -d "(" -f2 |
cut -d ")" -f1`
        Date=`who -a | grep -i $ID | awk '{print $4,$6}'`

cat << EOF
Date-Time :- $Date
username :- $user
IPAdd:- $IP
====================
EOF
done
else

echo "No ssh connection in Host"
fi

Wednesday 18 February 2015

Check latest line add in file.

#!/bin/bash

Latest_dir=/home/shashi/latest

diff=$(diff ${Latest_dir}/test* | sed 1d | sed 's/<//g' | sed '/^$/d' | sed 's/^ //g' | wc -l)

new=$(diff ${Latest_dir}/test* | sed 1d | sed 's/<//g' | sed '/^$/d' | sed 's/^ //g' | awk '{print FNR ")" $0}')

if [ 0 = "$diff" ]; then

    echo "not a add latest line in file"
else
    cat << EOF
Latest line is :-
${new}
EOF

cop=$(cp -rf ${Latest_dir}/test ${Latest_dir}/test1)

fi

Monday 16 February 2015

Script for Continue Copy Latest File.

#!/bin/bash
SOURCE=/home/shashi/data
R=/home/shashi/latest/first_log
D=/home/shashi/latest/second_log
DIST=/home/shashi/backup_latest
file=$(touch ${D})

while [ 0 = = 0 ]
do

$(find ${SOURCE} -mmin -1 | sed 1d > ${R})

DIF=$(diff ${R} ${D} | awk '{print $2}' | sed '/^$/d')

I=$(echo "${DIF}" > ${D})

        for copy in `cat $D`
        do
        cp -f $copy $DIST

        done
done