我使用paramiko
f.ex sudo apt-get update的sudo 命令遇到了一些问题
这是我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
这是一个快速代码.我知道我需要添加sys.exit(1)以及所有这些,但这仅仅是为了演示
我用这个作为参考: Jessenoller.com