SSH User name password login

Source: Internet
Author: User
Tags ssh

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 ' & '

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.