使用expect省去输入ssh密码之苦

来源:互联网 发布:国培网络研修心得体会 编辑:程序博客网 时间:2024/04/29 21:20
将ssh登录使用的Identity放到当前目录下,注意把权限改成600,然后执行下面的脚本,就可以在远程服务器上执行命令,而不用每次都输入密码。
 
#!/usr/bin/env expect
 
if {$argc < 2} {   #}\space{
  send_user "usage: $argv0 command\n"
  exit
}
 
set timeout 10
spawn ssh -i Identity -l root -p 22 192.168.10.10 $argv
expect "Enter passphrase for key*"
send "my password\n"
expect eof
原创粉丝点击