yum install -y expectlinux
自動遠程登陸vim
[root@aminglinux-02 sbin]# vim 1.expect #! /usr/bin/expect set host "192.168.133.132" set passwd "123456" spawn ssh root@$host expect { "yes/no" { send "yes\r"; exp_continue} // "password:" { send "$passwd\r" } } interact //腳本結束
加入執行權限bash
[root@aminglinux-02 sbin]# ./1.expect -bash: ./1.expect: 權限不夠 [root@aminglinux-02 sbin]# chmod a+x 1.expect
[root@aminglinux-02 sbin]# ./1.expect spawn ssh root@192.168.133.130 root@192.168.133.130's password: Last failed login: Wed Sep 20 23:31:03 CST 2017 from 192.168.133.131 on ssh:notty There was 1 failed login attempt since the last successful login. Last login: Wed Sep 20 22:29:52 2017 from 192.168.133.1 [root@aminglinux-01 ~]# ^C