Telnet安装和配置,脚本一键安装!

[cce]#!/bin/bash

#install the telnet service
#defaultly add a user to test:
#default_user: test default_passwd: test
set +H
config_file=/etc/xinetd.d/telnet
read -t 10 -p “installing now ?(y|n):” AN
case $AN in
n|N|no)
:;;
*)
echo “start installing…..”;sleep 2
yum install -y telnet-server
[ $? -ne 0 ]&& (echo “install fail…..”;exit 1)
echo “install secussfully….”;;
esac
echo “Start to config…”;sleep 3
sed -i ‘/disable/s/yes/no/’ $config_file
if [ $? -eq 0 ];then
sed -i ‘/disable/d’ $config_file
sed -i ‘/{/a//tdisable=no’ $config_file
read -t 20 -p “limit the accessing ip{y|n} ?” AN
fi
case $AN in
yes|y|Y)
while :
do
read -p “import the ip or network{eg 10.1.1.1 or 10.1.1.0/24}:” IP_NET
sed -i “/{/a/no_access=$IP_NET” $config_file
[ $? -eq 0 ]&&echo “Successfully……”
echo -e “/n”
read -t 10 -p “Go on ??(y|n):” answer
case $answer in
yes|y|Y)
continue;;
*)
break;;
esac
done;;
*)
echo -e “/n”;;
esac
read -t 20 -p “set the only ip or net to access?(y|n):” AN
case $AN in
yes|y|Y)
while :
do
read -p “import the ip or network{eg 10.1.1.1 or 10.1.1.0/24}:” IP_NET
sed -i “/{/a/only_from=$IP_NET” $config_file
[ $? -eq 0 ]&&echo “Successfully……”
echo -e “/n”
read -t 10 -p “Go on ??(y|n):” answer
case $answer in
yes|y|Y)
continue;;
*)
break;;
esac
done;;
*)
echo -e “/n”;;
esac
read -t 20 -p “if you need to change the port of telnet service?(y|n):” AN
case $AN in
Y|y|yes)
read -p “Import the port you want to change to:” PORT
echo “wait,changing…..”;sleep 2
sed -i “/^telnet/s/[0-9][0-9]*/$PORT/” /etc/services
([ $? -ne 0 ]&& echo “sorry the changing has failed!!! the port is still 22,you can change by yourself!!”)|| /
echo “Changing successfully !!! the port of telnet is $PORT now!! you had batter remember this!!!”;;
*)
echo -e “/n”;;
esac
echo “The firewall may stop the telnet service,stop them or import a rule to allow?”
select var in “Stop_firewall” “Import_A_rule” ;do
break
done
echo “now do as your choice :$var”;sleep 3
case $var in
“Stop_firewall”)
WORD=`service iptables status|grep -o stopped`
if [ -n $WORD ];then
echo “The firewall has been stopped….”
else
service iptables stop
([ $? -ne 0 ]&&echo “Failed…!! please do that by yourself….”)|| /
(echo “Successfully……”;sleep 1)
fi;;
*)
service iptables restart >/dev/null 2>&1
iptables -I INPUT 1 -p tcp –dport 22 -j ACCEPT
([ $? -ne 0 ]&&echo “Failed…!! please do that by yourself….”;sleep 1)|| /
echo “Successfully……”;;
esac
read -t 10 -p “If you want to let the root user to login?(y|n):” AN
case $AN in
y|Y|yes)
for((i=0;i<=3;i++))do echo “pts/$i”>>/etc/securetty;done
[ $? -eq 0 ]&&echo ” Sucessfully…..”;sleep 2;;
*)
:;;
esac
chkconfig –add telnet > /dev/null 2>&1
chkconfig –level 35 telnet on > /dev/null 2>&1
echo “Creating the user:test and the password is :test”| grep test –color=yes ;sleep 2
useradd test
passwd test>/dev/null 2>&1<<EOF
test
test
EOF
[ $? -eq 0 ]&& echo “User Creating Successfully…..”
read -t 6 -p “Start the sevice ?(y|n):” AN
case $AN in
N|n|no)
:;;
*)
echo -e “/n”
service xinetd start
[ $? -eq 0 ]&&echo “Successfully starting….”;sleep 3;;
esac
echo -e “now exiting….”;sleep 2[/cce]

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/58245.html

(0)
上一篇 2021年8月9日
下一篇 2021年8月9日

相关推荐

发表回复

登录后才能评论