Welcome to the Linux Foundation Forum!

ssh accept "yes" in automation script possible ?

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

Comments

  • Posts: 158
    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.
    1. #!/usr/bin/python
    2. import pexpect, sys, time, re
    3. SSH_NEWKEY = 'Are you sure you want to continue connecting'
    4.  
    5. ssh = pexpect.spawn('ssh user-name@%s'%(host))
    6. retval = ssh.expect([SSH_NEWKEY, '[Pp]assword:', pexpect.EOF, pexpect.TIMEOUT]
    7. , timeout = TIMEOUT)
    8. time.sleep(1)
    9.  
    10. if retval == 0:
    11. ssh.sendline ('yes')
    12. i = ssh.expect(['[Pp]assword: ', pexpect.EOF, pexpect.TIMEOUT], timeout = TIMEOUT)
    13. time.sleep(1)
    14. if i > 0:
    15. .....

    OR
    1. #!/usr/bin/expect
    2. ......
    3. proc myconnect { ip pass enable } {
    4. if { $ip != "" } {
    5. spawn ssh admin@$ip
    6. expect_before {
    7. "Connection closed by $ip" {
    8. catch { close -i $spawn_id }
    9. return 0
    10. }
    11. }
    12. expect {
    13. # anticipate connection issues along the way and not get hung up
    14. timeout {
    15. return 0
    16. }
    17. "Connection refused" {
    18. return 0
    19. }
    20. "Are you sure you want to continue connecting" {
    21. send "yes\r"
    22. exp_continue
    23. }
    24. "Do you want to change the host key on disk" {
    25. send "yes\r"
    26. exp_continue
    27. }
    28. .......

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training