问题描述:

I am writing a script to log into multiple Cisco routers. I am running into and issue. This message pops up every time. "The authenticity of host 'x.x.x.x (x.x.x.x)' cant be established RSA key fingerprint is X. Are you sure you want to continue connecting (yes/no)?

From everything I have read about this says this is normal for the first time sshing into it, but it should store the RSA key and no longer display this message. Is there anyway to stop this message from popping up?

Here is my code so far.

#!/usr/bin/expect -f

spawn ssh -l user x.x.x.x

sleep 3

expect "*word"

send "mypassword"

send \r

网友答案:

Add the following to your ssh options:

-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
网友答案:

Alternatively, to avoid host key verification and not use known_hosts file for a particular remote machine, you can also add the following to /etc/ssh/ssh_config:

Host remote_machine_ip
    StrictHostKeyChecking no
    UserKnownHostsFile=/dev/null

/etc/ssh/ssh_config - Golbal configuration
$HOME/.ssh/config - User-specific configuration

网友答案:

You can expect that prompt to occur, and actually answer it:

spawn ssh -l user x.x.x.x

expect {
    "connecting (yes/no)" {send "yes\r"; exp_continue}
    "password:"           {send "mypassword\r"}
}

exp_continue basically acts as a loop so that you can keep waiting for the password prompt.
If the "connecting" prompt does not occur, no problem: expect will see the password prompt and carry on.

相关阅读:
Top