我正在尝试通过 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/