Sunday, 21 October 2018

Linux two Face ssh authentication with centralized Database server

Create Databases :- 

  1. mysql -uroot -p
  2. create database Login;
  3. use Login;
  4. create table user (id int(10), Name varchar(25), Password varchar(25));
  5. insert into user (id,Name,Password) values (1,'mukesh','mukesh@123');
  6. exit

Copy Below script  :-


vim /tmp/Login.sh




#!/bin/bash
mukesh=`/usr/bin/ps ax | grep $$ | grep -v grep | awk '{ print $2 }'`
user=root                 #Databases UserName
password=Voip@90 #Database Password
DB=Login                 #Database Name
host=192.168.2.176 #Set Local or centralized Server Ip
while [ 1=1 ]
do
UserName=$(whiptail --inputbox "please enter your username" 8 78 --title "User Name" 3>&1 1>&2 2>&3)
                                                                        # A trick to swap stdout and stderr.
# Again, you can pack this inside if, but it seems really long for some 80-col terminal users.
exitstatus=$?
if [ $exitstatus = 0 ]; then

                Password=$(whiptail --passwordbox "please enter your Password" 8 78 --title "Password" 3>&1 1>&2 2>&3)
                if [ $exitstatus = 0 ]; then
        {
    for ((i = 0 ; i <= 100 ; i+=5)); do
        sleep 0.1
        echo $i
    done
} | whiptail --gauge "Please wait while we check..." 6 50 0

                IsUserExist=$(echo "SELECT count(*) as '' from user  WHERE Name='$UserName'  AND Password='$Password' limit 1 " | mysql $DB -u $user -p$password )
                        if [ "$IsUserExist" -eq 1 ] ;then
echo "Thanks for Login $UserName" > test_textbox
#                  filename height width
whiptail --textbox test_textbox 12 80
                        break
                        else
                        echo "You have enter wrong Username & Password." > test_textbox
#                  filename height width
whiptail --textbox test_textbox 12 80
                        logout=`/usr/bin/pkill -9 -t $mukesh`
                        continue
                        fi
                else
                logout=`/usr/bin/pkill -9 -t $mukesh`
                fi

else
    echo "User selected Cancel."
logout=`/usr/bin/pkill -9 -t $mukesh`
fi
done

Now Set This secprit  in .bashrc file 

/usr/bin/sh /tmp/Login.sh


Now if some one try login find below screen


Ask for User Name



   Ask For Password


   Success full authentication 



   If Enter Wrong User Name Or Password enter ok this ssh screen will terminated






No comments:

Step-by-step OpenLDAP Installation and Configuration on server

This tutorial describes how to install and configure an OpenLDAP server and also an OpenLDAP client. Step by Step Installation and Conf...