python - 如何通过 python (boto for AWS) 在交互式 shell 中运行命令

标签 python shell amazon-web-services ssh

我正在尝试通过 python boto ssh 模块(使用 paramiko 包)中的 ssh 远程运行一些命令到 AWS EC2 实例。我正在使用 boto.manage.cmdshell.sshclient_from_instance.run 工作正常,但问题是 .run 无法远程执行 sudo 命令。我收到此错误消息:

sudo: sorry, you must have a tty to run sudo  

我知道我可以手动登录并编辑权限来解决这个问题,但我也希望该部分能够自动化。我可以使用 .shell 启动交互式 shell,但是有没有办法使用 python 在该交互式 shell 中自动执行命令?

最佳答案

您应该使用boto.manage.cmdshell.SSHClient.run_pty(command)反而。它将请求一个伪终端并执行命令。

查看帖子How does paramiko Channel.recv() exactly work?了解如何读取标准输出。

关于python - 如何通过 python (boto for AWS) 在交互式 shell 中运行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33831487/

相关文章:

amazon-web-services - 不同地区 AmazonIpSpaceChanged 的​​ SNS 订阅错误

python - sklearn 的 make_blobs 和多元高斯有什么区别?

python - 获取 Linux Python 的通用操作系统名称

python - 在 python 中交互式地旋转 3D 图 - matplotlib - Jupyter Notebook

python - 如何在 python、odoo 中使用 For 循环正确计数?

shell - 如果shell中的大小非零,如何复制文件?

ios - 使用 xcodebuild 在模拟器上构建和运行应用程序

bash - 如果这些 Perl 命令在粘贴到 shell 中时被解释为 Bash 命令,是否有害?

amazon-web-services - AWS Cloud Formation 模板失败,指定的映射表达式参数无效

node.js - 通过 AWS Lambda 控制台编辑器导入模块