ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 通过expect实现ssh协议自动输密码

通过expect实现ssh协议自动输密码

原创 Linux操作系统 作者:神谕丶 时间:2015-03-19 11:39:45 0 删除 编辑


由于expect是基于tcl的,所以首先要安装tcl

我的环境是RHEL 6 + expect-5.43.0 + tcl8.4.19


首先tcl:
tar zxvf tcl8.4.19-src.tar.gz
cd tcl8.4.19/unix/
./configure
make && make install
安装完后pwd一下,等下configure expect时需要用到

然后expect:
tar zxvf expect-5.43.0.tar.gz
cd expect-5.43
#此处 --with-tclinclude 的路径为tcl目录下generic的绝对路径
./configure --with-tclinclude=/home/dev/software/tcl8.4.19/generic/ --with-tclconfig=/usr/local/lib/
make && make install

完成安装后,输入expect可以验证是否已经安装好



通过简单脚本就可以实现自动输入密码了:

#!/bin/bash
expect -c "
set timeout 5;
spawn /usr/bin/scp -r /home/dev/log dev@192.168.1.192:/home/dev/
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"yourpassword\r\";}    #修改成远程主机用户的密码
}
expect eof;"





来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29773961/viewspace-1465740/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: RHEL中yum命令介绍
请登录后发表评论 登录
全部评论
微信公众号:神谕的暗影长廊

注册时间:2014-07-28

  • 博文量
    161
  • 访问量
    1195299