SSH does not allow user name password login, then the big God told me that there is a expect can be achieved. Installing expect
Ubuntu installation, other please yourself Baidu
Apt-get Install expect
Use
The great God certainly has the demo, hehe, takes to direct use
Portal Https://github.com/wuhp/tools/tree/master/script
Glue it over one:
./remote_bash [IP] [user] [passwd] "[cmd]"
Log in with username user password passwd on the remote host IP and execute the XXX command
#!/usr/bin/expect-f
# Usage:
# /remote_bash [IP] [user] [passwd] "[cmd]"
# in this case, the command Lin e beginner should like ' [Root@localhost node]# ', ending with ']# '
if {$ARGC! = 4} {
Send_user "usage: $argv 0 i P User passwd cmd\n "
exit
}
set IP [lindex $argv 0] Set
user [lindex $argv 1]
set password [lindex $ARGV 2]
set cmd [lindex $argv 3]
set timeout-1
spawn ssh $user @ $ip
expect {
"*yes/no" {send "Y Es\r "; Exp_continue}
"*password:" {send "$password \ r"}
}
expect "*#"
send "$cmd \ r"
send " Exit\r "
expect EOF
Note: The fourth line may be an error, he matches the login to the command line after the prefix, not the root user to change to ' & '