expect 批量自动部署ssh 免密登陆 之 二
#!/usr/bin/expect -f
########################################## hutu
#Push the id.pas.pub public key to the target server through the SSH service to implement secret-free login.
#Define an iplist Create an iplist file in the current directory. The content format is: User Password IPaddress Port
#parameter: 1.user
# 2.password
# 3.ip
# 4.Por
##########################################
spawn ssh-keygen -t rsa
expect {
"*file in which to save the key*" {
send "\n\r"
send_user "/root/.ssh\r"
exp_continue
"*Overwrite (y/n)*"{
send "n\n\r"
}
}
"*Enter passphrase*" {
send "\n\r"
exp_continue
}
"*Enter same passphrase again*" {
send "\n\r"
exp_continue
}
}
set ip_file [open ./iplist r]
while {[gets $ip_file line] >= 0} {
set user [lindex $line 0]
set password [lindex $line 1]
set ip [lindex $line 2]
set port [lindex $line 3]
spawn ping ${ip} -w 2
expect {
-nocase -re "100% packet loss" {
send_error "Ping ${ip} is unreachable, Please check the IP address.\n"
exit 1
}
}
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user@$ip
expect {
#first connect, no public key in ~/.ssh/known_hosts
"Are you sure you want to continue connecting (yes/no)?" {
send "yes\r"
expect "password:"
send "$password\r"
}
#already has public key in ~/.ssh/known_hosts
"password:" {
send "$password\r"
}
}
puts "User: $user,\tPassword: xxxx,\tIP: $ip,\tPort: $port\n"
}
close $ip_file
expect 批量自动部署ssh 免密登陆 之 二的更多相关文章
- expect 批量自动部署ssh 免密登陆
[root@node2 ssh]# cat auto_ssh.sh #!/usr/bin/expect -f ########################################## #通 ...
- expect 批量自动部署ssh 免密登陆 之 三
#!/bin/expect -- ########################################## zhichao.hu #Push the id.pas.pub public k ...
- 批量部署ssh免密登陆
#!/bin/bash#set -xservers="10.254.192.xx10.254.192.xx10.254.192.xx"passwd="xxxxxxxx&q ...
- [提供可行性脚本] RHEL/CentOS 7 多节点SSH免密登陆
实验说明: 在自动化部署时,会经常SSH别的机器去操作,然而每次的密码认证却很令人烦躁,尤其是很长的密码,因此SSH免密登陆就显得必不可少: 在机器数目很多的时候,使用更过的往往是Ansible分发并 ...
- SSH免密登陆配置过程和原理解析
SSH免密登陆配置过程和原理解析 SSH免密登陆配置过很多次,但是对它的认识只限于配置,对它认证的过程和基本的原理并没有什么认识,最近又看了一下,这里对学习的结果进行记录. 提纲: 1.SSH免密登陆 ...
- 使用rsync基于ssh免密登陆进行备份或目录同步
日常工作中有很多的备份工作,rsync是一个很不错的工具,尝试使用基于ssh免密登陆的方式进行备份,测试成功,是可行且方便的方法,撰文记之,以备后用: 1.A主机root用户对B主机root用户做ss ...
- SSH免密登陆原理及实现
声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.SSH简介 SSH(Secure Shell)是一种通信加密协议,加密算法包括:RSA.DSA等. RSA:非对称加密算法,其安全性基于极其困难 ...
- ssh免密登陆:sshpass -p [passwd] ssh -p [port] root@192.168.X.X
正文: ssh免密登陆:sshpass -p [passwd] ssh -p [port] root@192.168.X.X
- ssh免密登陆配置
目录 ssh免密登陆 在A工作站上输入 B服务器上输入 登陆 ssh初次登陆询问 1.单次取消 2.ansible中增加链接参数 3.修改ansible配置参数[推荐] 4.修改服务器上的ssh_co ...
随机推荐
- Python----简单线性回归
简单线性回归 1.研究一个自变量(X)和一个因变量(y)的关系 简单线性回归模型定义:y=β0+β1x+ε 简单线性回归方程:E(y)=β0+β1x 其中: β0为回归线的截距 β1为回归线的斜率 ...
- 微信中如何做到访问app的下载链接时直接跳到默认浏览器去执行下载
在我们使用微信营销的时候,很容易碰到H5链接在微信内无法打开或在微信内无法打开app下载页的情况.通常这种情况微信会给个提示 “已停止访问该网址” ,那么导致这个情况的因素有哪些呢,主要有以下四点 1 ...
- JS中的事件委托(事件代理)
一步一步来说说事件委托(或者有的资料叫事件代理) js中事件冒泡我们知道,子元素身上的事件会冒泡到父元素身上. 事件代理就是,本来加在子元素身上的事件,加在了其父级身上. 那就产生了问题:父级那么多子 ...
- JavaScript加载次序问题
3个文件,一个index.html如下 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&quo ...
- springboot项目中配置swagger-ui
Git官方地址:https://github.com/SpringForAll/spring-boot-starter-swagger Demo:https://github.com/dyc87112 ...
- Linux 下安装idea,提示svn版本太低问题
在 RedHat 6.5 虚拟机上装了 Idea 2017, 将项目代码从 Windows 共享到虚拟机中,然后 Idea 提示 svn 版本太旧, 上网查资料说 Idea 2018 不支持1.7以下 ...
- [搬运] 将 Visual Studio 的代码片段导出到 VS Code
原文 : A Visual Studio to Visual Studio Code Snippet Converter 作者 : Rick Strahl 译者 : 张蘅水 导语 和原文作者一样,水弟 ...
- js获取当前url
1.window.location.href(设置或获取整个 URL 为字符串) 2.window.location.protocol(设置或获取 URL 的协议部分) 3.window.locati ...
- Java程序设计第一次作业
虽说这学期Java比上学期的C语言要简单些许,但是初次面对java程序,还是有点难度的.
- wireshark 过滤表达式
一.针对wireshark最常用的自然是针对IP地址的过滤.其中有几种情况: (1)对源地址为192.168.0.1的包的过滤,即抓取源地址满足要求的包. 表达式为:ip.src == ...