expect 传递出错,显示 Permission denied, please try again

出现问题:

[root@arslinux-01 expect]# ./3.expect root 192.168.194.132 "ls;w;vmstat 1"

spawn ssh [email protected]

[email protected]'s password: yum

Permission denied, please try again.


现象:

[root@arslinux-01 expect]# vim 3.expect

#!/usr/bin/expect

set user [lindex $argv 0]

set host [lindex $argv 1]

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 [email protected]

[email protected]'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 [email protected]

[email protected]'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]# 


猜你喜欢

转载自blog.51cto.com/11530642/2411737