shell脚本通过expect实现自动单边无密登录
2017-01-03 16:08
666 查看
最近项目需要实现单边无密登录,去网上搜索了下相关文章,实践之后发现几乎都不能用。于是结合expect的使用方法自行写了一个,通过验证可用。现在总结在这供需要的朋友参考。
代码如下:
代码如下:
EXPECT=/usr/bin/expect
$EXPECT <<EOF spawn ssh-keygen -t rsa expect "*ssh/id_rsa*" { send -- "\r" expect "*for no passphrase*" send -- "\r" expect "*passphrase again*" send -- "\r" exp_continue } EOF iplist=`cat /root/ip.list` for ip in $iplist do $EXPECT <<EOF spawn ssh-copy-id root@$ip expect "*(yes/no)?*" { send -- "yes\r" expect "*?assword:*" send -- "$PASSWD\r" } "*?assword:*" { send -- "$PASSWD\r" exp_continue } EOF done
相关文章推荐
- shell脚本通过expect实现自动单边无密登录功能
- 用expect实现的自动登录到多台服务器的shell脚本
- shell脚本通过expect脚本实现自动输入密码
- 用expect实现的自动登录到多台服务器的shell脚本
- shell脚本通过expect脚本实现自动输入密码(使用expect)
- 在shell脚本中利用expect实现自动应答
- 【转】在shell脚本中利用expect实现自动应答
- Shell 和 Expect 脚本的自动登录运行
- 通过在shell脚本中用expect实现远程scp文件
- 通过 Shell 和 Expect 脚本实现对 IBM 刀片服务器高级管理模块固件的大量升级
- shell脚本实现ssh自动登录功能分享
- shell + expect 自动登录并执行脚本
- shell+expect实现多台服务器自动运行脚本。
- 通过Git WebHooks+脚本实现自动更新发布代码之shell脚本
- shell中实现自动登录(bash环境脚本中)
- Linux中使用expect脚本实现远程机器自动登录
- 通过脚本自动设置,批量实现免密码登录主机
- shell脚本实现ssh自动登录功能分享
- Linux中使用expect脚本实现远程机器自动登录
- 无密钥登录的自动脚本实现(ssh-copy-id、expect免交互输入脚本)