johnyang
johnyang

Reputation: 21

When I try to use linux expect to ssh remote machine, the authentication is very slow ,why?

I try to use it , but I find It is very slow .

my code:

#!/usr/bin/expect -f
set hostname [lindex $argv 0]
spawn ssh "xxx\@$hostname"
expect "password: "
send "xxxxx\r"
expect "$ "
send "sudo su admin\r"
expect "assword:\n"
send "xxxxx\r"
expect "$ "
send "cat /tmp/id_rsa.pub >> /home/admin/.ssh/authorized_keys\r"
expect "$ "
send "exit\r"

Do you have any suggestion?

Upvotes: 0

Views: 2137

Answers (2)

mrpezzal
mrpezzal

Reputation: 11

Try

ssh -o GSSAPIAuthentication=no login@remoteipipaddress

if successful.. need to edit /etc/ssh/ssh_config and /etc/ssh/sshd_config and looking for GSSAPIAuthentication. Please change value to "no".

it's working for me.

Upvotes: 0

glenn jackman
glenn jackman

Reputation: 247042

Add exp_internal 1 to the top of your script so you can watch what expect is doing.

I suspect this is wrong: expect "assword:\n" -- I bet the actual password prompt does not end with a newline. Try removing \n

Upvotes: 1

Related Questions