CentOS中文网

CentOS 6.7编写Shell脚本实现简单跳板机功能

CentOS中文网 https://www.centos.net.cn 2015-11-30 01:05 出处:网络 编辑:@iCMS
1、分发密钥(使用普通用户) ssh-keygen-tdsa-P''-f~/.ssh/id_dsa ssh-copy-id-i.ssh/id_dsa.pub172.16.1.7

1、分发密钥(使用普通用户)

ssh-keygen-tdsa-P''-f~/.ssh/id_dsa

ssh-copy-id-i.ssh/id_dsa.pub172.16.1.7

ssh-copy-id-i.ssh/id_dsa.pub172.16.1.8

2、编写脚本

[root@m01profile.d]#cat/server/scripts/tiaoban.sh

#!bin/sh

functiontrapper(){

trap''INTQUITTSTPTERMHUB

}

functionmenu(){

cat<<-EOF

==============HostList==============

1-172.16.1.7/24

2-172.16.1.8/24

0-Exitsystem

=====================================

EOF

}

functionhost(){

case"$1"in

1)

ssh$USER@172.16.1.7

;;

2)

ssh$USER@172.16.1.8

;;

0)

exit0

esac

}

functionmain(){

whiletrue

do

trapper

clear

menu

read-p"Plsinputyourchoice:"num

host$num

done

}

main

[root@m01profile.d]#cat/etc/profile.d/tiaoban.sh

[$UID-ne0]&&

./server/scripts/tiaoban.sh

3、用普通用户登录跳板机测试,效果图如下:

CentOS 6.7编写Shell脚本实现简单跳板机功能

0

精彩评论

暂无评论...
验证码 换一张
取 消