Linux under the Fortress machine certification

Source: Internet
Author: User

Linux under the Fortress machine certification

Add your own authentication mechanism to control the users of SSH to a Linux machine.

For example, the permission to log on to the Linux host for three users.

The user name and password are as follows.

Lucy:123

ben:456

jerry:789

If a user enters a password error three times, the user account is locked.


That is, verify before SSH is logged in.

The script is as follows

Accountfile= is defined by itself.


# PRE


if [!-e $AccountFile];then

Cat > $AccountFile <<eof

lucy:123:0

ben:456:0

jerry:789:0

Eof


Fi if the file does not exist, use the default

# main Process

While True;do

Echo-e "\033[32m Welcome to Linux club\033[0m" Output welcome menu

Read-p "Please input your username:" username

Accountuser= ' awk-f: ' {print $ ' $AccountFile ' awk gets the first column of the file and gets the user name

# echo account user is $AccountUser

For name in $AccountUser;d o traverse the user name of the file to find the same as the user input

if [x$name = = X$username];then

pass=$ (grep $username $AccountFile |awk-f: ' {print $} ')

count=$ (grep $username $AccountFile |awk-f: ' {print $} ')

If [$Count-lt 3];then Verify that the number of times the password has been wrong is less than three times

Read-s-P "Please input your passwd:" passwd

echo ""

if [X$pass = = x$passwd];then

Sed-i "/$username/s/:[0-9]$/:0/" $AccountFile password is correct, set the number of errors 0

Echo Welcome

Bash

Else

echo Wrong Pass

Let count= $Count +1

Sed-i "/$username/s/:[0-9]$/: $Count/" $AccountFile write the number of errors back to the file

Break

Fi

Else

Echo Your account has been locked

Exit 5

Fi

Fi

Done

Done



Add the script into the/etc/profile.

sh/root/xcui/account.sh


Then ssh in the results of the operation as follows:

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/9C/3D/wKiom1ltzVXhcEc1AAAjpqPzwmE925.png-wh_500x0-wm_ 3-wmp_4-s_3327524203.png "title=" 3.png "alt=" Wkiom1ltzvxhcec1aaajpqpzwme925.png-wh_50 "/>

Enter the correct password to enter bash

650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M02/9C/3D/wKioL1ltzcmy5awmAABM8BAIl1M905.png-wh_500x0-wm_ 3-wmp_4-s_1352065329.png "title=" 4.png "alt=" Wkiol1ltzcmy5awmaabm8bail1m905.png-wh_50 "/>

Enter the wrong password, greater than three times when the account is locked.


Linux under the Fortress machine certification

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.