Linux Shell ssh登录脚本
Linux 登陆服务器敲命令太多,某时候确实不便,所以就用shell写了一个
我的blog地址: http://www.cnblogs.com/caoguo

一.说明
- 支持秘密和密钥两种格式
- 用户名和密码都是写文件的,明文保存
二.配置
- 密码文件配置:
序号:IP:端口:用户:密码:说明 1:192.168.88.128:22:root:toor:虚拟机web服务器
- 密钥文件放在keys文件夹下,密码位置写成密钥文件名,文件名必须以.pem结尾
github地址:https://github.com/ca0gu0/so
脚本下载:git clone git@github.com:ca0gu0/so.git
补充:
发现没有代码还是不好,把代码还是贴上
so.sh文件的内容
#!/bin/bash direc=`dirname $`
function color(){
blue="\033[0;36m"
red="\033[0;31m"
green="\033[0;32m"
close="\033[m"
case $ in
blue)
echo -e "$blue $2 $close"
;;
red)
echo -e "$red $2 $close"
;;
green)
echo -e "$green $2 $close"
;;
*)
echo "Input color error!!"
;;
esac
} function copyright(){
echo "#####################"
color blue " SSH Login Platform "
echo "#####################"
echo
} function underline(){
echo "-----------------------------------------"
} function main(){ while [ True ];do echo "序号 | 主机 | 说明"
underline
awk 'BEGIN {FS=":"} {printf("\033[0;31m% 3s \033[m | %15s | %s\n",$1,$2,$6)}' $direc/password.lst
underline
read -p '[*] 选择主机: ' number
pw="$direc/password.lst"
ipaddr=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $2}}' $pw)
port=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $3}}' $pw)
username=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $4}}' $pw)
passwd=$(awk -v num=$number 'BEGIN {FS=":"} {if($1 == num) {print $5}}' $pw) case $number in
[-]|[-][-]|[-][-][-])
echo $passwd | grep -q ".pem$"
RETURN=$?
if [[ $RETURN == ]];then
ssh -i $direc/keys/$passwd $username@$ipaddr -p $port
echo "ssh -i $direc/$passwd $username@$ipaddr -p $port"
else
expect -f $direc/ssh_login.exp $ipaddr $username $passwd $port
fi
;;
"q"|"quit")
exit
;; *)
echo "Input error!!"
;;
esac
done
} copyright
main
ssh_login.exp 这个一个expect脚本,用户写交互的工具
#!/usr/bin/expect -f
set TARGET [lindex $argv ]
set USER [lindex $argv ]
set PASSWD [lindex $argv ]
set PORT [lindex $argv ]
set timeout spawn ssh $USER@$TARGET -p $PORT
expect {
"*yes/no" {send "yes\r"; exp_continue}
"*password:" {send "$PASSWD\r"}
}
interact
password.lst密码文件格式
:192.168.88.128::root:toor:虚拟机web服务器
:192.168.88.130::ca0gu0:toor:虚拟机mysql数据库服务器
:192.168.88.4::root:sellercube:本地开发服务器



Linux Shell ssh登录脚本的更多相关文章
- linux shell except tcl login ssh Automatic interaction
/*************************************************************************************** * linux she ...
- Linux Shell脚本攻略 读书笔记
Linux Shell脚本攻略 读书笔记 这是一本小书,总共253页,但内容却很丰富,书中的示例小巧而实用,对我这样总是在shell门前徘徊的人来说真是如获至宝:最有价值的当属文本处理,对这块我单独整 ...
- 73条日常Linux shell命令汇总,总有一条你需要!
转载: 73条日常Linux shell命令汇总,总有一条你需要! 1.检查远程端口是否对bash开放: echo >/dev/tcp/8.8.8.8/53 && echo &q ...
- Linux shell用法和技巧(转)
原文出处: techbar 译文出处: 外刊IT评论 使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和技巧.当然,命令我能记住,但我不敢说能记得如何用它执行某 ...
- Linux shell 常用
使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和l技巧.当然,命令我能记住,但我不敢说能记得如何用它执行某个特定任务.于是,我开始在一个文本文件里记录这些用法,并 ...
- 详细介绍Linux shell脚本基础学习
Linux shell脚本基础学习这里我们先来第一讲,介绍shell的语法基础,开头.注释.变量和 环境变量,向大家做一个基础的介绍,虽然不涉及具体东西,但是打好基础是以后学习轻松地前提.1. Lin ...
- Linux shell用法和技巧
使用Linux shell是我每天的基本工作,但我经常会忘记一些有用的shell命令和l技巧.当然,命令我能记住,但我不敢说能记得如何用它执行某个特定任务.于是,我开始在一个文本文件里记录这 ...
- Linux shell日常命令和技巧
转自:http://www.vaikan.com/linux-shell-tips-and-tricks/ 原文:http://www.techbar.me/linux-shell-tips/ 使用L ...
- Linux shell入门基础(一)
Linux shell入门基础(一): 01.增加删除用户: #useradd byf userdel byf(主目录未删除) userdel -r byf 该用户的属性:usermod 用 ...
随机推荐
- PHP array_pad()
定义和用法 array_pad() 函数向一个数组插入带有指定值的指定数量的元素. 语法 array_pad(array,size,value) 参数 描述 array 必需.规定数组. size 必 ...
- ZOJ 3201
id=15737" target="_blank">Tree of Tree Time Limit: 1000MS Memory Limit: 32768KB ...
- 编程算法 - 求1+2+...+n(函数继承) 代码(C++)
求1+2+...+n(函数继承) 代码(C++) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 求1+2+...+n, 要求不能使用乘除法\for\whi ...
- LeetCode 648. Replace Words (单词替换)
题目标签:HashMap 题目给了我们一个array 的 root, 让我们把sentence 里面得每一个word 去掉它得 successor. 把每一个root 存入hash set,然后遍历s ...
- Java程序执行超时——Future接口介绍
在Java中,如果需要设定代码执行的最长时间,即超时,可以用Java线程池ExecutorService类配合Future接口来实现. Future接口是Java标准API的一部分,在java.uti ...
- 怎样设置mysql远程訪问
Mysql默认是不能够通过远程机器訪问的,通过以下的配置能够开启远程訪问 在MySQL Server端: 运行mysql 命令进入mysql 命令模式, mysql> use mysql; ...
- Codeforces Round #319 (Div. 1)C. Points on Plane 分块思想
C. Points on Plane On a pl ...
- 【CodeForces】166'E
166’E Tetrahedron You are given a tetrahedron. Let’s mark its vertices with letters A, B, C and D co ...
- 0606-工厂模式、单例模式、DBDA的单例和完整功能
工厂模式:只要指定类名,就可以据此获取一个该类的对象. 单例模式:某个类,只允许其“创建”出一个对象. 单例的方法:三私一公(一个私有化对象,一个私有化构造方法,一个私有化克隆方法,一个公共方法返回对 ...
- [Swift通天遁地]五、高级扩展-(4)快速生成Invert、Mix、Tint、Shade颜色及调整饱和度阶
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...