批量配置SSH 免密钥登录脚本
来源:互联网 发布:模拟退火算法应用实例 编辑:程序博客网 时间:2024/05/16 17:49
[root@c3-zabbix-serv hurl]# cat sendsshkey.sh
#!/bin/bash
if [ -z $1 ]; then
echo "Usage : sh $0 username passwd"
echo "Example: sh $0 root 'passwd!@#2015'"
fi
function sendSSHKey(){
SSH='ssh-copy-id -i'
HOME_DIR=`cd ~ && pwd`
KEYSTORE=$HOME_DIR/.ssh/id_rsa.pub
# $SSH $KEYSTORE ${1}@${2}
# 三个参数是'user'--'ip'--'password'
echo "========$# -- $1 -- $2 -- $3 ========="
if [ ! $2 ] || [ ! $3 ] ;then
echo "ip/password not found !"
exit
else
expect -c "
spawn $SSH $KEYSTORE ${1}@${2}
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"$3\r\"; exp_continue}
\"*Password*\" {send \"$3\r\";}
}
"
echo -e "\033[40;32m send sshkey to $2 success \033[0m\n"
fi
}
#读取一行数据,用i做形参
cat ./hostlist.txt |while read i
do
USER=$1
#从'hostlist.txt'文件中寻找IP
IP=`echo $i | awk '{print $1}'`
#echo " $# -- $1 -- $2"
#如果有一个参数,则从'hostlist.txt'文件中寻找密码
if [ $# -eq 1 ];then
PASSWORD=`echo $i | awk '{print $2}'`
#如果有两个参数,把第二个参数当作密码
elif [ $# -eq 2 ];then
PASSWORD=$2
else
exit
fi
sendSSHKey $USER $IP $PASSWORD
done
====================================
使用命令:
0 0
- 批量配置SSH 免密钥登录脚本
- 配置ssh免密钥登录
- ssh 配置免密钥登录
- SSH免密钥登录
- SSH免密钥登录
- ssh免密钥登录
- ssh免密钥登录
- 批量配置计算机集群SSH免登录
- ssh密钥登录认证自动配置脚本
- linux免密钥ssh登录
- ssh 免密码登录 密钥登录
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)
- Linux设置ssh免密钥登录
- liunx SSH密钥 免密码登录
- Linux下ssh免密钥登录
- Ubuntu配置ssh密钥登录
- Linux ssh免密钥登陆配置
- CentOS7下配置SSH免密钥登陆
- [ViewController respondsToSelector:]: message sent to deallocated instance 问题
- Android获取View宽高的几种方式
- UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)-转
- JQuery点击复制文本框内容的方法插件
- 我的第一个struts 例子
- 批量配置SSH 免密钥登录脚本
- MyBatis动态SQL之 set 和 trim标记的使用
- Android进程/线程通信方式
- JPush推送
- 百炼OJ1004
- 淘宝CDN架构全解析
- IOS 用 xcode 设置 开机启动页
- Qt程序移植到ARM板上去掉鼠标样子
- java设计模式之单例篇