擅长:python、mysql、java
<p>你会发现有两件事很有用:</p>
<ol>
<li><p><code>exec_command</code>接受<code>get_pty</code>的可选参数。你可以这样使用它:</p>
<pre><code>(stdin, stdout, stderr) = ssh.exec_command("sudo ls", get_pty = True)
</code></pre></li>
<li><p>将密码放入<code>stdin</code>,并返回一行并刷新以确保它被传递。这可以确保它在请求时收到密码(你可以做一些更复杂的事情来检查它是否真的请求了。。。只是简单地把它扔进去,对我来说并没有什么问题。)</p>
<pre><code>stdin.write('passwd' + '\n')
stdin.flush()
</code></pre></li>
</ol>
<p>综合起来,这些应该可以解决您的<code>sudo</code>超过<code>paramiko</code>的问题。在</p>