python - 通过 ssh 打开另一个处理程序到 python 中的远程主机

标签 python linux authentication ssh

我有一个 Controller ,我使用 IP 和密码通过 ssh 访问。进入 Controller 后,我需要打开另一个处理程序来访问 linux 命令。要访问此处理程序,我需要以 root 身份登录并提供密码。 我将如何在 python 中使用 ssh 来做到这一点?

Login to controller as
user: root
password: root
Inside Controller 
<cntrlprompt># logas root
Password:123456
After this step it would provide bash prompt
bash# ls -al
<capture ls -al output and return to main program.

这对我来说非常具有挑战性,如有任何帮助,我将不胜感激。 谢谢

最佳答案

pexpect可能是你想要的。它是一个 python 库,允许您编写 shell 交互脚本。这是 example说明匿名 ftp session 。学习它并构建您自己的交互场景应该相当容易。

关于python - 通过 ssh 打开另一个处理程序到 python 中的远程主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22676327/

相关文章:

python - 如何在 pygame 窗口和函数之间转换

linux - 如何删除目录中的所有空文件?

linux - 在 bash 中运行多个进程

android - 如何制作启用单点登录的 facebook 应用程序?

Django 和 CouchDB - 通用身份验证后端

c# - 访问文件夹时,Web 浏览器控件身份验证不起作用

python - RxPY - flat_map 发射等待下一个生成器值

python - 如何从 DB 或 draw.io 图表生成 SQLAlchemy 代码?

php - 读取由 PHPExcel 修改的 .xls 文件时 xlrd 崩溃

c++ - Gearman 客户端在网页中失败,但在命令行界面中成功?