出現問題:linux
[root@arslinux-01 expect]# ./3.expect root 192.168.194.132 "ls;w;vmstat 1"vim
spawn ssh root@192.168.194.132bash
root@192.168.194.132's password: yumssh
Permission denied, please try again.ide
現象:測試
[root@arslinux-01 expect]# vim 3.expectspa
#!/usr/bin/expectit
set user [lindex $argv 0]io
set host [lindex $argv 1]ast
set passwd "123456"
set cm [lindex $argv 2]
spawn ssh $user@$host
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect "]*"
send "$cm\r"
expect "]*"
send "exit\r"
[root@arslinux-01 expect]# chmod a+x 3.expect
[root@arslinux-01 expect]# ./3.expect root 192.168.194.132 "ls;w;vmstat 1"
spawn ssh root@192.168.194.132
root@192.168.194.132's password:
Permission denied, please try again.
解決方法:
在 expect 執行的這臺機器上
vim /etc/ssh/sshd_config
找到 PermitRootLogin 取消註釋,並改成 yes
PermitRootLogin yes
重啓 sshd
問題應該能夠解決
測試
[root@arslinux-01 expect]# ./3.expect root 192.168.194.132 "ls;w;vmstat 1"
spawn ssh root@192.168.194.132
root@192.168.194.132's password:
Last failed login: Thu Jun 20 22:51:10 CST 2019 from 192.168.194.130 on ssh:notty
There were 19 failed login attempts since the last successful login.
Last login: Thu Jun 20 21:36:31 2019 from 192.168.194.130
[root@arslinux-02 ~]# ls;w;vmstat 1
20190526.log 419.TXT anaconda-ks.cfg linux2019
23:00:41 up 2:18, 2 users, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.194.1 21:00 10:41 0.10s 0.10s -bash
root pts/1 192.168.194.130 23:00 0.00s 0.03s 0.01s w
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
2 0 264 130220 0 292416 0 0 34 65 83 161 0 1 99 0 0
0 0 264 130232 0 292444 0 0 0 13 73 138 0 0 100 0 0
0 0 264 130264 0 292444 0 0 0 12 75 138 0 1 99 0 0
^C[root@arslinux-01 expect]#