【发布时间】:2011-02-08 14:56:22
【问题描述】:
我在使用 paramiko 使用 sudo 的命令时遇到一些问题
f.ex sudo apt-get update
这是我的代码:
try:
import paramiko
except:
try:
import paramiko
except:
print "There was an error with the paramiko module"
cmd = "sudo apt-get update"
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect("ip",username="lexel",password="password")
print "succesfully conected"
except:
print "There was an Error conecting"
stdin, stdout, stderr = ssh.exec_command(cmd)
stdin.write('password\n')
stdin.flush()
print stderr.readlines()
print stdout.readlines()
这是一个快速代码。我知道我需要添加 sys.exit(1) 和所有这些,但这只是为了演示
我用这个作为参考: Jessenoller.com
【问题讨论】:
-
这本质上是Paramiko and Pseudo-tty Allocation 的副本。我建议您阅读该问题的答案:)。
-
我回答的另一个非常相似的问题是here