Linux.com

Home Linux Community Forums Software Command Line ssh accept "yes" in automation script possible ?

ssh accept "yes" in automation script possible ?

Link to this post 03 Jun 10

ssh accept "yes" in automation script possible ?

With the help of ssh i am executing the script...

Before executing the ssh command, at very first time i need to do ssh manually and typing "yes" to accept RSA key fingerprint...Can we do it through automation by passing yes as an argument...

$
The authenticity of host 'hostname (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is 83:71:28:7c:55:38:28:4e:9e:51:32:57:19:9e:d2:d9.
Are you sure you want to continue connecting (yes/no)? yes

Link to this post 12 Jun 10

Yes you can.

Try launching it from expect, or using an expect module for your favorite scripting language. I do this all the time in python, and in regular tcl/expect.


#!/usr/bin/python
import pexpect, sys, time, re
SSH_NEWKEY = 'Are you sure you want to continue connecting'

ssh = pexpect.spawn('ssh user-name@%s'%(host))
retval = ssh.expect([SSH_NEWKEY, '[Pp]assword:', pexpect.EOF, pexpect.TIMEOUT]
, timeout = TIMEOUT)
time.sleep(1)

if retval == 0:
ssh.sendline ('yes')
i = ssh.expect(['[Pp]assword: ', pexpect.EOF, pexpect.TIMEOUT], timeout = TIMEOUT)
time.sleep(1)
if i > 0:
.....

OR


#!/usr/bin/expect
......
proc myconnect { ip pass enable } {
if { $ip != "" } {
spawn ssh admin@$ip
expect_before {
"Connection closed by $ip" {
catch { close -i $spawn_id }
return 0
}
}
expect {
# anticipate connection issues along the way and not get hung up
timeout {
return 0
}
"Connection refused" {
return 0
}
"Are you sure you want to continue connecting" {
send "yes\r"
exp_continue
}
"Do you want to change the host key on disk" {
send "yes\r"
exp_continue
}
.......

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board