利用expect script实现ssh免密码登录

  • Post author:
  • Post category:其他


一、安装expect

1. Linux下:

sudo apt-get install expect

2. Cygwin下:

apt-cyg install expect

二、编写expect script

1. 新建文件run.ex

2. 添加如下代码

#!/usr/bin/expect
set user Username
set password Password
set host Server  
set timeout -1 
spawn ssh $user@$host
match_max 100000
expect "*?assword:*"
send -- "$password\r"
interact

三、运行

./run.ex



版权声明:本文为Geurney原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。