使用shell脚本配合jumpserver自动登录服务器

@努力的小王  March 23, 2018

1.生产服务器的ssh一定是不允许通过客户端直接连接服务器的,需中间加一个jumpserver做堡垒机,一般是客户端通过vpn(openvpn等)首先拨号连接jumpserver。
2.写一个shell脚本(非常简单)

#!/bin/env bash
##this is user automatic logon scipts
##author xw 2018.3.23
trap "" 1 2 3 20 ##捕捉到信号不退出
while :
do
cat <<-EOF
     1. web1
     2. web2
     3. mysql
EOF

read -p "input number[1-3]: " num
case "$num" in
1)
      ssh root@192.168.187.139
      ;;
2)
      ssh root@192.168.187.130
      ;;
3)
      ssh root@192.168.187.140
      ;;
esac
done


3.在用户(当前使用的用户环境下)配置
ssh-keygen
ssh-copy-id root@192.168.187.130
ssh-copy-id root@192.168.187.139
做公钥免密码登录


添加新评论