我对使用 paramiko 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