标签:搭建ssh跳板机
搭建ssh跳板机
环境介绍:
[root@localhost ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@localhost ~]# uname -r 2.6.32-504.el6.x86_64
//准备2-3台虚拟机,至少2台。
1.在所有机器上创建跳板机用户
[root@localhost ~]# useradd tb [root@localhost ~]# echo "123.com"|passwd --stdin tb
2.在跳板机上创建密钥
[root@localhost ~]# su - tb [root@localhost ~]# ssh-keygen -t dsa -P -f ~/.ssh/id_dsa
//将生成密钥拷贝到需要通过跳板机登录的机器上。
[root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub "-p 22 tb@192.168.75.141" [root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub "-p 22 tb@192.168.75.140" [root@localhost ~]# ssh-copy-id -i .ssh/id_dsa.pub "-p 22 tb@192.168.75.139"
3.创建跳板机脚本
[root@localhost ~]# cd /server/scripts
[root@localhost ~]# vim tiaoban.sh
#!/bin/bash
function trapper(){
  trap ‘‘ INT QUIT TSTP TERM HUP
}
function menu(){
    cat <<-EOF  <==前面是一个减号
=========Host List==========
    1)192.168.75.141
    2)192.168.75.140
    3)192.168.75.139
    4)exit
=============================
    EOF  <===EOF前面是一个tab键,非4个空格。
}
function host(){
   case "$1" in
     1)
      ssh $USER@192.168.75.141
      ;;
     2)
      ssh $USER@192.168.75.140
      ;;
     3)
      ssh $USER@192.168.75.139
      ;;
    4|*)
      exit
      ;;
    esac
}
function main(){
  while true
  do
    trapper
    clear
    menu
    read -p "Please select:" num
    host $num
  done
}
main
:wq 保持退出4.添加登录系统加载脚本
[root@localhost ~]# cd /etc/profile.d/ [root@localhost ~]# vim tiaoban.sh #添加如下内容 [ $UID -ne 0 ] && [ $UID -ne 500 ]&&. /server/scripts/tiaoban.sh #已知root用户UID为0,oldboy用户UID为500,这些用户不要进入跳板机系统。
5.下面测试。使用xshell登录跳板机。
本文出自 “小曾” 博客,请务必保留此出处http://zengxin.blog.51cto.com/6098070/1890655
标签:搭建ssh跳板机
原文地址:http://zengxin.blog.51cto.com/6098070/1890655