使用Popen的Python SSH

2024-06-03 05:06:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我如何使用ssh使用Popen在面对这个问题时默认回答是?在

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)?

这就是我要做的

^{pr2}$

Tags: ofthekeyyouhostisbeecdsa
2条回答

不确定子流程是如何做到的,下一步是另一种方法,可能对您有帮助。仅供参考。在

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("192.168.1.6", 22, "username", "password")
stdin, stdout, stderr = ssh.exec_command('ls') // your command here
content = stdout.readlines()
print content
ssh.close()

从手册页:

StrictHostKeyChecking

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

如果希望ssh/scp在不提示的情况下自动接受新密钥,可以将StrictHostKeyChecking设置为“no”。在命令行上:

scp -o StrictHostKeyChecking=no ...

也可以启用批处理模式:

^{pr2}$

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).

相关问题 更多 >