Python SSH using Popen
<p>How do I <code>ssh</code> using <code>Popen</code> by answering yes by default when faced with this?</p>

<pre><code>The authenticity of host '`XXXXX`' can't be established.
ECDSA key fingerprint is SHA256:LA2RqbdzD8Uxgi36KWOM12giS9T+ceOQYhYjVKReMks.
Are you sure you want to continue connecting (yes/no)?
</code></pre>

<p>this is what I'm trying</p>

<pre><code>for IP in ['10.32.253.250']:
    remoteCall = subprocess.Popen(["ssh", "co_user@"+IP, "sudo svstat /etc/sv/nagios_CheckDisk_Alertz_daemon",], stdout=subprocess.PIPE, stderr=subprocess.PIPE);
    Response, err = remoteCall.communicate()
    if(re.search("authenticity of host", Response)):
        stdin.write('yes')
    print IP + "  " +Response
</code></pre>

<p>From the man page:</p>

<blockquote>
  <p>StrictHostKeyChecking</p>
  
  <p>If this flag is set to âyesâ, ssh(1) will never automatically add host
  keys to the ~/.ssh/known_hosts file, and refuses to connect to hosts
  whose host key has changed. This provides maximum protection against
  trojan horse attacks, though it can be annoying when the
  /etc/ssh/ssh_known_hosts file is poorly maintained or when connections
  to new hosts are frequently made. This option forces the user to
  manually add all new hosts. If this flag is set to ânoâ, ssh will
  automatically add new host keys to the user known hosts files. If this
  flag is set to âaskâ, new host keys will be added to the user known
  host files only after the user has confirmed that is what they really
  want to do, and ssh will</p>
</blockquote>

<p>You can set StrictHostKeyChecking to "no" if you want ssh/scp to automatically accept new keys without prompting. On the command line:</p>

<pre><code>scp -o StrictHostKeyChecking=no ...
</code></pre>

<p>You can also enable batch mode:</p>

<pre><code>BatchMode
</code></pre>

<blockquote>
  <p>If set to âyesâ, passphrase/password querying will be disabled. This
  option is useful in scripts and other batch jobs where no user is
  present to supply the password. The argument must be âyesâ or ânoâ.
  The default is ânoâ. With BatchMode=yes, ssh/scp will fail instead of
  prompting (which is often an improvement for scripts).</p>
</blockquote>

python ssh subprocess popen