码迷,mamicode.com
首页 > 其他好文 > 详细

服务器免密登陆脚本

时间:2018-09-29 19:20:04      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:eof   password   usr   space   source   time   ted   org   bsp   

yum install -y tcl tclx tcl-devel

wget http://sourceforge.net/projects/expect/files/Expect/5.45/expect5.45.tar.gz/download

tar xzvf download

cd expect5.45

./configure

make && make install

ln -sf /data/expect5.45/libexpect5.45.so  /usr/lib64/libexpect5.45.so

expect

 

vim autossh.sh

 

#!/usr/bin/expect

set timeout 10 

set username [lindex $argv 0]

set password [lindex $argv 1]

set hostname [lindex $argv 2]

spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $username@$hostname

expect {

    "*assword" {send "$password\r";}

    "yes/no" {send "yes\r";exp_continue}

}

expect eof

 

chmod +x autossh.sh

 

./autossh.sh root password ip

服务器免密登陆脚本

标签:eof   password   usr   space   source   time   ted   org   bsp   

原文地址:https://www.cnblogs.com/bhan/p/9725210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!